witt Posted June 6, 2006 Share Posted June 6, 2006 When someone logs in, this is set:$_SESSION['user_id'] = $row[0];If the user is logged in and a script like this script is run:$location_id = $_GET['id']; require_once ('includes/mysql_connect.php'); $query = "SELECT location, user_id FROM locations WHERE location_id='$locaton_id'"; $result = mysql_query ($query); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_array ($result, MYSQL_NUM); $location = $row[0]; $user_id = $row[1]; } echo $user_id;The user id of the person who's viewing the page is displayed while it should be the person selected from the database. If no one is logged in, the correct user id is shown. If, $user_id = $row[1]; and echo $user_id; are changed to anything else, like $hello = $row[1]; and echo $hello; everything works well. Link to comment https://forums.phpfreaks.com/topic/11315-strange-session-problem/ Share on other sites More sharing options...
shocker-z Posted June 6, 2006 Share Posted June 6, 2006 I also had this problem in a script that was very long and it took me days to realise it kinda sets sessions as a global but i'm also not sure why...Maby someone can enlighten us?RegardsLiam Link to comment https://forums.phpfreaks.com/topic/11315-strange-session-problem/#findComment-42381 Share on other sites More sharing options...
witt Posted June 6, 2006 Author Share Posted June 6, 2006 any other ideas? Link to comment https://forums.phpfreaks.com/topic/11315-strange-session-problem/#findComment-42445 Share on other sites More sharing options...
dckarina Posted June 6, 2006 Share Posted June 6, 2006 hello,i'm just learning php but from what i've read if you have register_globals in php.ini set as ON then you can acces a session variable - in your case user_id - only by using it's name (without using $_SESSION['name']). so, from what i can see, and if php is like other programming languages, your user_id variable (inside IF) is just local and if you have register_globals on then you will acces the session variable called user_id. i'm not 100%. corect me if i'm wrong. hope this helps.Karina Link to comment https://forums.phpfreaks.com/topic/11315-strange-session-problem/#findComment-42452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.