Page 1 of 1

URL help

Posted: Fri Feb 28, 2003 9:53 am
by gennusa
How do I get my file to get the current URL (that is being viewed), parse it and display only the variable to the page?

Posted: Fri Feb 28, 2003 10:38 am
by pootergeist
echo $_SERVER['REQUEST_URI'];

that'll output the current top document request call (query string included)

next bit...

just output the variable ? or the value of the variable ?

foreach($_GET as $var=>$val)
{
echo $var.'<br />';
}

well, that's the get variables echoed. If you didn't mean that, please explain better.

Posted: Fri Feb 28, 2003 10:40 am
by McGruff
$_SERVER['QUERY_STRING'] might be what you're looking for - or the $_GET array, as mentioned above.

See php manual "predefined variables" for full info.

Re the code above:

Code: Select all

foreach($_GET as $var=>$val) 
{ 
echo $var.'<br />'; 
}
Isn't that just echoing out the keys?

If you want to declare the vars (you might not need to) try:

Code: Select all

foreach($_GET as $var=>$val) 
{ 
$$var = $val; 
}
You might want to do some processing on GET vars for security reasons but I'm still figuring that out.

Posted: Fri Feb 28, 2003 11:05 am
by gennusa
Thank you for your help.

This is what worked:

http://www.site.com?number=3

echo $_GET['number'];

------displays------------

3