Welcome to WebmasterWorld Guest from 54.146.221.231

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

take keywords from url, use them on page

     
1:28 am on Jul 4, 2007 (gmt 0)

New User

10+ Year Member

joined:Aug 19, 2005
posts:10
votes: 0


how can i do the following...

user types in my www.mydomain.com/anywordhere

how can i echo the 'anywordhere' onto the page?

thanks!

2:16 am on July 4, 2007 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12533
votes: 0


Welcome to WebmasterWorld, invisible777.

You should be able to parse out the pieces you need from one of PHP's $_SERVER [php.net]superglobal variables.

2:43 am on July 4, 2007 (gmt 0)

New User

10+ Year Member

joined:Aug 19, 2005
posts: 10
votes: 0


Hi, thanks for the reply. I have this piece of code:

<?PHP
$keys = explode("-",str_replace(array("http://",".php"),"",$_SERVER['SCRIPT_URI']));
echo $keys[0]."<br>".$keys[1];?>

which requires the page exist... whereas i just need something that allows the user to type in www.mydomain.com/absolutelyanythinghere and then i suppose to be redirected to an index.php where 'absolutelyanythinghere' can be echoed onto the page...

1:46 pm on July 4, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 22, 2005
posts:152
votes: 0


you can pass that string to index.php as parameter

e.g
redirect www.example.net/index.php?invalidpage=absolutelyanythinghere

and then in index.php
use get to get paremeter

$string = $_GET['invalidpage'];

then display value of the variable
echo $string;

3:39 pm on July 4, 2007 (gmt 0)

New User

10+ Year Member

joined:Aug 19, 2005
posts:10
votes: 0


sorry im not following... how does that redirect occur if the original invalid page does not exist?
7:02 pm on July 4, 2007 (gmt 0)

Full Member

10+ Year Member

joined:Jan 4, 2006
posts:307
votes: 0


You need to add the following code to your .htaccess file.

RewriteEngine on
RewriteRule ^([^/]+)$ /index.php?invalidpage=$1 [L]

And your index.php will be

print $_GET['invalidpage'];

Milan