BenMo Posted April 30, 2007 Share Posted April 30, 2007 I've run into a very weird error. I found a way to work around the problem, but I don't understand why it was a problem in the first place. I'm creating a login system using SESSION and MySql calls, and there is an overlap in the variables, meaning that it seems php thinks that a $_SESSION var and a $php var are the same variable. session_start(); $myusername=$_SESSION['username']; $mypassword=$_SESSION['password']; $host="localhost"; // Host name $username="BenMo"; // Mysql username $password="something"; // Mysql password $db_name="homeBase"; // Database name $tbl_name="Users"; // Table name // Connect to server and select databse. $con = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); What is strange is that the var $_SESSION['username'] gets set to the $username var after this code runs. So when the page loads, $_SESSION['username'] is storing the value "BenMo", instead of what used to be in the session var. If I change $username to something else, like $username2, then there isn't a problem. There isn't code here or anywhere else that assigns a value to the $_SESSION['username'] var. Does anyone know what's going on? Link to comment https://forums.phpfreaks.com/topic/49268-mysql-and-session-var-overlap-php-bug/ Share on other sites More sharing options...
trq Posted April 30, 2007 Share Posted April 30, 2007 Does anyone know what's going on? Do you have register globals switched on? Link to comment https://forums.phpfreaks.com/topic/49268-mysql-and-session-var-overlap-php-bug/#findComment-241401 Share on other sites More sharing options...
BenMo Posted April 30, 2007 Author Share Posted April 30, 2007 Hmm, I don't know what register globals are, so perhaps this is the problem. Any guesses on what the default problem would be if I haven't changed anything? Link to comment https://forums.phpfreaks.com/topic/49268-mysql-and-session-var-overlap-php-bug/#findComment-241409 Share on other sites More sharing options...
trq Posted April 30, 2007 Share Posted April 30, 2007 What is the output of.... <?php echo ini_get('register_globals'); ?> ? Link to comment https://forums.phpfreaks.com/topic/49268-mysql-and-session-var-overlap-php-bug/#findComment-241418 Share on other sites More sharing options...
btherl Posted April 30, 2007 Share Posted April 30, 2007 register_globals would be the default problem if you haven't changed anything It causes exactly the problem you describe. When the script starts, it sets your standard variables from the values in $_SESSION, $_GET, $_POST and $_COOKIE according to a fixed set of rules (the rules can be changed also, if you're that keen). Some people like it for the convenience, but it's safer to switch it off if you are able to. And indeed they are the same variables. If you modify $username, then you will be modifying $_SESSION['username'] (providing it existed in $_SESSION when you called session_start()). A variable which hasn't been placed in $_SESSION will not magically appear in $_SESSION however, which makes sense. Link to comment https://forums.phpfreaks.com/topic/49268-mysql-and-session-var-overlap-php-bug/#findComment-241443 Share on other sites More sharing options...
BenMo Posted April 30, 2007 Author Share Posted April 30, 2007 Good to know. Thanks so much! That was confusing the hell out of me. Link to comment https://forums.phpfreaks.com/topic/49268-mysql-and-session-var-overlap-php-bug/#findComment-241554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.