Take the following PHP snippet:
Code: Select all
if ($id) {
do something
} else {
printf("<a href=\"%s?id=1\">click</a>", $PHP_SELF);
}
With PHP 4.2.0 and above, the variable "register_globals" is off by default for security reasons. There is a massive amount of discussion over this but, essentially, there are good reasons for doing this. The "downside" of this, however, is that the above code won't work. The URL will not set the session variable to "1". I refused to change the setting to "on" because I didn't want to just bypass the issue, but determine how to do things properly.
After over an hour and a half (!) of trying to come up with a simple solution to the problem, I finally stumbled on an answer. Notice the additional line of code at the beginning:
Code: Select all
$id = $_GET["id"];
if ($id) {
do something
} else {
printf("<a href=\"%s?id=1\">click</a>", $PHP_SELF);
}