Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use $cat instead of $_GET['cat']

Status
Not open for further replies.

plarsen

Programmer
Jul 30, 2002
27
DK
Hi

I have a shopping system, that has several $ command but it will not work. I can use $_GET command however, but the other command is much easier to use and remember.

Are there anyone who can explain why i can't use then $ command anymore?

Thanks

Peter Larsen
 
Change "register_globals" to "ON" in you php.ini. It's not recommended, since anyone can set values for your internal variables. Be careful to initialize *every* variable before you use it if you do this.
 
You can also use:
Code:
if (!empty($_GET))extract($_GET);
if (!empty($_POST))extract($_POST);
at the top of your code which will populate the variables for you, but you run into the same security concerns as setting "register_globals" to "ON".

Ken
 
knirke

As well as making your code more secure (see the link provide by aardvark92 above), use of the superglobals[ul][li]makes your code more portable. The superglobals are always available (assuming PHP version > 4.1.0), whereas the "field" variables may not be, depending on configuration.[/li][li]more maintainable. With a complex script, six months from now you may have no idea how the value got into $foo. But $_POST['foo'] is pretty obvious.[/li][/ul]

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top