Register_Globals off
Quote: Originally Posted By ROB in Thread PHP Cookies (Really this time!)
ALWAYS get your data from $HTTP_GET_VARS(or $_GET), $HTTP_POST_VARS(or $_POST), $HTTP_COOKIE_VARS(or $_COOKIE), or the all-encompassing $_REQUEST.
Recently, we leased a dedicated server with php 4.1 and when I started transferring php scripts to it, much to my surprise did I discover that nothing worked anymore. After doing a quick bit of research, discovered that the guilty culprit is the subject of this post. Fortunatly, simply by adding 'php_flag register_globals on' into my .htaccess file solved the immediate problem.
However, in an effort to start complying with the fact that this function may become depracated as well as being somewhat of a security risk, I have started doing some research and maybe I'm missing a good resource somewhere, but everything I have found on php.net is really vague about how to use the functions in Rob's post.
So I'm going to give a scenario and if someone would like to give a simple example of how to do this or even post a URL that has a good tutorial, would be greatly appreciated.
SCENARIO:
Web pages:
test.php
test2.php
Variables in test.php:
$foo="foo"
$bar="bar"
What do I need to do in test.php to pass these variables to test2.php without passing them in the URL (test2.php?foo=$foo&bar=$bar), via a form or in a Cookie.
How do I get them and display them in test2.php
Thanks,
Dan
Recycle Video Games Network
Stupidity killed the cat, curiosity was framed!
nike_guy_man posted this at 19:49 — 26th June 2002.
They have: 840 posts
Joined: Sep 2000
You could use include/require or something like it
<?php
test2.php:
require('test.php');
?>
How's that work for you?
zollet posted this at 19:58 — 26th June 2002.
He has: 1,016 posts
Joined: May 2002
If you would like to use cookies, here's some simple sample of code..
<?php
// In test.php
setcookie(\"foo\", \"foo\");
setcookie(\"bar\", \"bar\");
// Or a little more advanced..
setcookie(\"foo\", \"foo\", \"\", \"/\", \"domain.com\");
setcookie(\"bar\", \"bar\", \"\", \"/\", \"domain.com\");
// In test2.php
$foo = $_COOKIE[\"foo\"];
$bar = $_COOKIE[\"bar\"];
?>
You can find more information about cookies on http://www.php.net/manual/en/function.setcookie.php
cds posted this at 20:13 — 26th June 2002.
They have: 359 posts
Joined: Mar 1999
In response to nike_guy_man:
If they were static variables like my example, yes you could, but in the real world scenario that I need to start converting, the variables are all dynamic, are different for each user and used in a shopping cart to identify user info throughout the various cart scripts.
In response to zollett:
Cookies are an option, but isn't really the way I want to pass variables. Have discovered that there are always a few people out there that think cookies are the "Great Evil" and disable them. Shopping cart uses cookies now, but in a very limited basis and never in an important area of the cart. Just to identify returning customers. All important areas currently pass the variables in the link url or via form input.
Dan
Recycle Video Games Network
Stupidity killed the cat, curiosity was framed!
zollet posted this at 20:19 — 26th June 2002.
He has: 1,016 posts
Joined: May 2002
You could also use sessions. If you've compiled PHP with --enable-trans-sid, then if the user don't accept cookies, it will automatically put the session info in the URL. Very useful feature. Also this way you don't store any information on the user's computer, everything is stored on the server.
nike_guy_man posted this at 20:58 — 26th June 2002.
They have: 840 posts
Joined: Sep 2000
I use sessions for my site for dynamic info
I'd suggest using that
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.