PHP Variables Issue

prateems32

New Member
Messages
14
Reaction score
0
Points
1
I'm having a problem with the following code:

PHP:
<?php # Script - index.php

if (isset($var)) {
   // Check to see if the variable $var is given a value...
   /* ... */ # <-- Bunch of PHP code to be executed if condition is met.
} else {
   // If $var hasn't been defined...
   echo "<a href=\"index.php?var=yes\">Set variable var=\"Yes\"</a>";
}

?>

Now, I'm trying to migrate web-hosts from a different host to x10hosting, but I need to be able to run this kind of script. x10hosting has better features offered, so I definitely want to stick to it. On my prior web-host, this script works perfectly fine with no reported errors, but upon uploading of the exact same file to this server, I run into the following problem:

On loading the page (index.php), it executes the else part of the if() statement, but when I click on the link, it does not work as it should. It keeps taking me to the correct page (index.php?var=yes), where $var is defined, but continues running the else part of the if() statement.

This is a big issue for me because my script uses a bunch of these kinds of statements.

Any help would be appreciated. Thanks!

- Prateem Shrestha

---------- Post added at 05:22 AM ---------- Previous post was at 05:10 AM ----------

Based on the related threads links, it's probably because register_globals is turned off...

I'll try using $_GET['var'] in a temporary version of my script to see if it works and update accordingly. Cheers :)

---------- Post added at 05:28 AM ---------- Previous post was at 05:22 AM ----------

Yep, using $_GET['var'] worked perfectly fine.
Now I know. :p
 
Last edited:

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
Why was register_globals turned on on your old host?! It can lead to many problems and sometimes security flaws - always use $_GET or $_POST accordingly.

~Callum
 

prateems32

New Member
Messages
14
Reaction score
0
Points
1
Can it really? I'm not too knowledgeable about the issue. Well, the more I know, heh.
Mmm I figured it'll probably be good practice for me to always use $_GET['var'] instead of just $var when I need to, after I made the changes.

Not too sure why it was turned on for my previous host, though.
 
Top