Jump to content

Strange session problem


witt

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

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.