Session Variable being lost
I've got a session variable being registered on a PHP page.
When a user follows a link to the next page, the session is no longer available.
I'm using session_start(); at the top of my page, and the second page is within the same domain/directory.
Does anyone know what could be causing the loss of session?
Same bad results before and after the change
I have this in an HTML form:
<input type="text" name="username">
Then I have this in a PHP script:
$username = $_POST['username'];//the unique username
Then I possibly corrupt it here:
require 'aFile.php';
Because aFile.php has:
$username = "theSharedMySQLusername";
mysql_connect($primary, $username, $password)...
(although I do not save it in a session at this point)
But the 1st strange thing is that after the require, I have:
$sql = mysql_query("SELECT * FROM UserTable WHERE User = '$username'");
Yet it apparently is using the unique username in the query since theSharedMySQLusername would return no rows, and later it shows that I am logged in as the unique username
(This may be a scoping issue against what the docs say -- the query should have used theSharedMySQLusername).
Then I set the session variable:
$_SESSION['username']=$username;
I figured I was storing the corrupted username here, so I changed $username to $uniqueUsername above in 3 places:
$uniqueUsername = $_POST['username'];//the unique username
$sql = mysql_query("SELECT * FROM UserTable WHERE User = '$uniqueUsername'");
$_SESSION['username']=$uniqueUsername;
Then I display who is logged in on an HTML page using the session variable. First it shows the unique username, then if I go to a different page and return, it shows theSharedMySQLusername.
Very frustrating.
Re: Same bad results before and after the change
Quote:
Originally posted by Phenix
I have this in an HTML form:
<input type="text" name="username">
Then I have this in a PHP script:
$username = $_POST['username'];//the unique username
Then I possibly corrupt it here:
require 'aFile.php';
Because aFile.php has:
$username = "theSharedMySQLusername";
mysql_connect($primary, $username, $password)...
(although I do not save it in a session at this point)
But the 1st strange thing is that after the require, I have:
$sql = mysql_query("SELECT * FROM UserTable WHERE User = '$username'");
Yet it apparently is using the unique username in the query since theSharedMySQLusername would return no rows, and later it shows that I am logged in as the unique username
(This may be a scoping issue against what the docs say -- the query should have used theSharedMySQLusername).
Then I set the session variable:
$_SESSION['username']=$username;
I figured I was storing the corrupted username here, so I changed $username to $uniqueUsername above in 3 places:
$uniqueUsername = $_POST['username'];//the unique username
$sql = mysql_query("SELECT * FROM UserTable WHERE User = '$uniqueUsername'");
$_SESSION['username']=$uniqueUsername;
oh man, I just noticed that you set it twice. the last one will overwrite the posted one.
you have this subbmitted
$username = $_POST['username'];//the unique username
but then you include a file that inlcudes this
$username = "theSharedMySQLusername";
you can't do that, change the name.. and most of it is in my post above this one. once you submit the form since register_globals are on then $username is filled by that and still used. and changed by mysql variable