1. Home
  2. Computing & Technology
  3. PHP / MySQL

How do I pass variables in the URL in PHP 5?

By Angela Bradley, About.com

Question: How do I pass variables in the URL in PHP 5?

If you pass variables in the URL in PHP4, and then move your scripts to a server running PHP5, you may notice they no longer work. Things such as www.yoursite.com/script.php?color=red in PHP4 would automatically assign $color = red.... how can you make it work in PHP5?

Answer: PHP5 is also capable of handling variables in this manor. The difference is that register_globals is turned OFF in php.ini by default in PHP5, and turned ON by default in PHP4. To make the passed variables work you have two options:

1.) Turn register_globals ON in the php.ini file

or

2.) Use $_GET['var'] In our example of www.yoursite.com/script.php?color=red you would use:

$color = $_GET['color']

More PHP / MySQL Q&A

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Troubleshooting
  5. Passing variables in PHP 5 in the URL

©2008 About.com, a part of The New York Times Company.

All rights reserved.