PHP Noob Question

Soldato
Joined
30 Nov 2005
Posts
3,084
Location
London
Just a quickie.

Just wondered what’s going on when you see this (example):

user.php?name=david

Is there a specific term for this?

Cheers
 
Briefly, it's a way of sending external data to the server to be processed by a script or program on the server.

In that example, the part of the url starting with the ? is the query string, and contains a variable called name with a value of david to be processed by the script user.php. You can have multiple variables [normally] connected by ampersands e.g. ?name=david&gender=male&age=42.

In PHP, such variables are accessed using the 'superglobal' array $_GET. So,
Code:
<?php echo $_GET['name']; ?>
would print out david.

http://hudzilla.org/phpwiki/index.php?title=The_superglobal_arrays
http://uk.php.net/variables.external
 
Just be careful that if you're going to use this method to transfer data from page to page as the data forms part of the url and can be accessed - so dont use it to send sensitive info
 
Hyzepher said:
Just be careful that if you're going to use this method to transfer data from page to page as the data forms part of the url and can be accessed - so dont use it to send sensitive info

POST can be just as easily hijacked too, though. The real moral is that if you're using anything that could have even the remotest possibility of being user-changeable, you must always treat it as if it's dangerous until you've made sure it isn't.
 
JamesU2005 said:
Just a quickie.

Just wondered what’s going on when you see this (example):

user.php?name=david

Is there a specific term for this?

Cheers

Is it likely the "david" is stored in a database or is stored in user.php with a long list of names and it just limits it to "david" (if that's possible, if so how)?
 
What I mean is that the "david" is obvisuoly used to identify something and will present the data associated with it.

E.g. Look at the OC website:
overclockers.co.uk/showproduct.php?prodid=GX-035-BG

What would be a rough idea of the php used here?
 
each product is in a table in a database.

Each product has an ID, when you click a product its ID is taken from the database and then on the next page all the information linking to that specific ID is shown.

unless you mean how does it know which ID information it is meant to show ?

It gets the ID, puts it in the URL, then the next page searches the URL for a product ID then displays the info about that one, if theres no productID there it will revert to a not found page or a default index page
 
Back
Top Bottom