I don't understand really how session variables work so prior to explaining my problem; I'll let you know where I currently stand.
I setup my site to use templates. At the top of each page there are includes, to include the headers, logon form, and navigation tabs.
1. I included session_start in my header template right before it sends anything to the browser.
2. After the header loads, then I include "templates\forms\logon.php" this is a form that allows the user to login. Once the logon is successful, $_SESSION['username'] = $_POST['username'].
Now that 1 and 2 are both done,
I show a form to the user to enter stuff, when I go to enter stuff into the database; I added this.
$requester = $_SESSION['username'];
It keeps return NULL!?!?
Now the weird thing is that what I stated above, 2., shows "Welcome tmaiden"
It pulls the tmaiden from $_SESSION['username']; in a seperate file "templates\forms\logon.php"
But when "templates\forms\logon.php" is loaded on the page with the form to enter other stuff, $_SESSION['username'] returns NULL
Any suggestions?
THanks.
Losing Session Variable, Kinda
Moderator: General Moderators
WTF!
I now added a text box,
<input type="text" name="test" value="<? echo $_SESSION['username']; ?>"><br/>
And it shows the user name; but yet this doesn't work
I now added a text box,
<input type="text" name="test" value="<? echo $_SESSION['username']; ?>"><br/>
And it shows the user name; but yet this doesn't work
Code: Select all
if(isset($_SESSION['username'])){
$requester = $_SESSION['username'];
}
else{
$requester = 'Anonymous';
}
$query = "INSERT INTO ff_people (name, requester, status, ranking, timestamp)
VALUES('" . $personname . "', '" . $requester . "', 0, 0, Now())";
mysql_query($query) or die(mysql_error());
mysql_close();Now this works.
But why doesn't this work?
Code: Select all
<input type="hidden" name="requester" value="<? echo $_SESSION['username']; ?>">
....
if(isset($_POST['requester'])){
$requester = $_POST['requester'];
}
else{
$requester = 'Anonymous';
}
$query = "INSERT INTO ff_people (name, requester, status, ranking, timestamp)
VALUES('" . $personname . "', '" . $requester . "', 0, 0, Now())";Code: Select all
if(isset($_SESSION['username'])){
$requester = $_SESSION['username'];
}
else{
$requester = 'Anonymous';
}
$query = "INSERT INTO ff_people (name, requester, status, ranking, timestamp)
VALUES('" . $personname . "', '" . $requester . "', 0, 0, Now())";