Seperating superglobals

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
tommy1987
Forum Commoner
Posts: 92
Joined: Tue Feb 21, 2006 8:35 pm

Seperating superglobals

Post by tommy1987 »

Hi,

I want to seperate out superglobals to read them in again, like the following:


http://www.blahblah.co.uk/blah.php?id=4565np=123123

where id and np should be read into a form and their respective values. PHP doesnt seem to recognise that they are both individual and cant distinguish that id=4565 and np=123123.

Hope someone can help, im sure its extremely simple, Thanks, Tom
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

PHP distinguishes querystring parameters through get. In your case (blah.php?id=4565np=123123) checking for these vars in the superglobal array $_GET would easily reveal their values to you.

Code: Select all

<?php
if (isset($_GET['id']))
{
    echo $_GET['id'] . ' is the id var value...<br />';
}

if (isset($_GET['np']))
{
    echo $_GET['np'] . ' is the np var value...<br />';
}
?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You would use $_GET, but you need to separate the name=value pairs with ampersands, such as:

Code: Select all

www.blahblah.co.uk/blah.php?id=4565&np=123123
(#10850)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I don't think Everah noticed the missing ampersand. :roll: (just to make sure the poster doesn't get confused with extra info)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Got that right. Looked right over it. 8O
Post Reply