URL help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gennusa
Forum Newbie
Posts: 9
Joined: Thu Feb 20, 2003 4:27 pm
Location: Delaware, USA
Contact:

URL help

Post 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?
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Last edited by McGruff on Thu Aug 11, 2005 2:20 pm, edited 1 time in total.
gennusa
Forum Newbie
Posts: 9
Joined: Thu Feb 20, 2003 4:27 pm
Location: Delaware, USA
Contact:

Post by gennusa »

Thank you for your help.

This is what worked:

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

echo $_GET['number'];

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

3
Post Reply