Subscribe to Tutorial Feed

Flash and PHP Bible

The Flash and PHP Bible has been released! The book can be found on Amazon or wherever fine books are sold in your area.

The Flash and PHP Bible has a forum for quick support.

Scriptplayground » tutorials » php » Query Strings

Query Strings

The following article is an explantion on query strings


'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.

Follow Scriptplayground on Twitter (@scriptplay)

Comments: Query Strings

 Gixboy  Sun Jan 29, 2006 11:17 pm  
Thank you a lot. This is the first place that I've found, including Barnes and Noble at my downtown mall, that could give me a simple, to-the-point tutorial on query strings in php. This has made my links go a lot faster, and it saves me annoying "Page Cannot Be Displayed"'s. Good job.
 mkeefe  Thu Feb 2, 2006 1:25 am  
Glad that the tutorial helped you out. It is always nice to hear comments back from the readers. :)
 somone  Mon Oct 8, 2007 7:11 am  
hi, thanks for help
Add a comment
The ability to add new comments has been disabled in this archived version.

Main | Tutorials | Articles