Jump to content


This topic is now archived and is closed to further replies.


Strange session problem

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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?


Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.