problem with session varaibles
-
What I'm trying to do should be simple but for some reason it's not. All I want right now is to display one of my session variables on the page (this way I know it's what I think it is). I have
<td><input name="myusername" type="text" id="myusername" style="width:150px"></td>
on the first form to get the value and thensession_register("myusername");
on the next page to assign the value to the session variable. I then have (this is the very top of the page (page 3))<?php
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
session_start();
if (!session_is_registered(myusername)) {
header("location:login.php");
}
?>
Test
<?php
$test = $_SESSION["myusername"];
echo $test;
?>On the "last" page... the page isn't redirecting so I know the value is "good" but for some reason I can't get it to display. It's just displaying 'Test'...
-
What I'm trying to do should be simple but for some reason it's not. All I want right now is to display one of my session variables on the page (this way I know it's what I think it is). I have
<td><input name="myusername" type="text" id="myusername" style="width:150px"></td>
on the first form to get the value and thensession_register("myusername");
on the next page to assign the value to the session variable. I then have (this is the very top of the page (page 3))<?php
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
session_start();
if (!session_is_registered(myusername)) {
header("location:login.php");
}
?>
Test
<?php
$test = $_SESSION["myusername"];
echo $test;
?>On the "last" page... the page isn't redirecting so I know the value is "good" but for some reason I can't get it to display. It's just displaying 'Test'...
-
What I'm trying to do should be simple but for some reason it's not. All I want right now is to display one of my session variables on the page (this way I know it's what I think it is). I have
<td><input name="myusername" type="text" id="myusername" style="width:150px"></td>
on the first form to get the value and thensession_register("myusername");
on the next page to assign the value to the session variable. I then have (this is the very top of the page (page 3))<?php
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
session_start();
if (!session_is_registered(myusername)) {
header("location:login.php");
}
?>
Test
<?php
$test = $_SESSION["myusername"];
echo $test;
?>On the "last" page... the page isn't redirecting so I know the value is "good" but for some reason I can't get it to display. It's just displaying 'Test'...
I figured out my problem... as usual forgot the most simple aspect of programming :wtf:
$_SESSION['myusername'] = $myusername;
I really does help to actually assign a value to something... Hopefully this will help someone else that finds them self in the same lack of sleep state. -
5.1.6 However stupid here realized that he forgot to actually assign the session variable a value. I guess the important thing is I figured it out :laugh:
-
5.1.6 However stupid here realized that he forgot to actually assign the session variable a value. I guess the important thing is I figured it out :laugh:
-
Since php version 5.3 don't forget that "session_register" has been deprecated and removed for version 6.0 so be caution of this gotcha!
Thanks for the FYI, I'll account for it now before I forget about it.
-
What I'm trying to do should be simple but for some reason it's not. All I want right now is to display one of my session variables on the page (this way I know it's what I think it is). I have
<td><input name="myusername" type="text" id="myusername" style="width:150px"></td>
on the first form to get the value and thensession_register("myusername");
on the next page to assign the value to the session variable. I then have (this is the very top of the page (page 3))<?php
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
session_start();
if (!session_is_registered(myusername)) {
header("location:login.php");
}
?>
Test
<?php
$test = $_SESSION["myusername"];
echo $test;
?>On the "last" page... the page isn't redirecting so I know the value is "good" but for some reason I can't get it to display. It's just displaying 'Test'...
Even though you seem to have found a solution, I have actually found some web hosting to be quite a pain if you are using Sessions. Depends on the provider though. With my current provider it was becoming way to complicated to set up properly so I used another method
Thomas Williams - Chimp Twist
-
Even though you seem to have found a solution, I have actually found some web hosting to be quite a pain if you are using Sessions. Depends on the provider though. With my current provider it was becoming way to complicated to set up properly so I used another method
Thomas Williams - Chimp Twist
This is just for a small intranet site. I think the most users I've ever had on at one time is 5 :) However I'm always looking for ideas.
-
This is just for a small intranet site. I think the most users I've ever had on at one time is 5 :) However I'm always looking for ideas.
Good luck with intranet site :)hope you don't find too many more issues. On my website in the end I reverted to cookies. When the user logs in it stores the information they typed in the form in 2 cookies (nom). Then every time any page loads I check it against the database, thus maintaining some form of security :)
Thomas Williams - Chimp Twist
-
Good luck with intranet site :)hope you don't find too many more issues. On my website in the end I reverted to cookies. When the user logs in it stores the information they typed in the form in 2 cookies (nom). Then every time any page loads I check it against the database, thus maintaining some form of security :)
Thomas Williams - Chimp Twist
I was having a heck of a time with cookies in a terminal services environment. Not really sure why that made a difference, but maybe I'll look back into that again in the future.