Scriptplayground

 Print Page | Close Window

Query Strings

The following article is an explantion on query strings

<?php
http://www.yoursite.com/page.php?url=portfolio
?>


'query string' is the ?url=portfolio part in 'page.php?url=portfolio'. url=portfolio 
is called a variable/value pair. You can seperate them by using an '&' ampersand 
EX: 'page.php?var1=gallery&var2=3d'.

That is what a query string is, but how does PHP read this you ask? Read on.



we use the $_GET array!

The GET array is used in place of the original variable.



print $_GET['url'] . '<br />';

print $_GET['id'] . '<br />';

print $_GET['page'] . '<br />';

That is an example $_GET array being printed in PHP



include $_GET['url'];

This is the most common use of query strings, but that example is highlighting an extremely dangerous way of doing it. Check out the Secure Navigation tutorial here for more info.



Now you should understand how Query Strings work.


Find this article at:
http://scriptplayground.com/tutorials/php/Query-Strings/