CMDAI
asked on
$_SESSION does not retain variables
i have no idea what happened or how to fix this
but my website was working fine and all out of sudden all the users got logged out
i traced it down to that $_SESSION does not retain variables
for testing i created a file called
test.php
with only this code inside
<?php
session_start();
echo $_SESSION['abc'];
$_SESSION['abc'] = 123;
?>
if i reload the page i get
abc=
and thats it.
but my website was working fine and all out of sudden all the users got logged out
i traced it down to that $_SESSION does not retain variables
for testing i created a file called
test.php
with only this code inside
<?php
session_start();
echo $_SESSION['abc'];
$_SESSION['abc'] = 123;
?>
if i reload the page i get
abc=
and thats it.
huh?
you mean this????
<?php
session_start();
$_SESSION["abc"] = 123;
echo "<BR />";
echo "abs is= " . $_SESSION["abc"];
?>
you mean this????
<?php
session_start();
$_SESSION["abc"] = 123;
echo "<BR />";
echo "abs is= " . $_SESSION["abc"];
?>
ASKER
no i mean what i wrote actually
echo session_start(); //returns true if session was succefully started/resumed
echo "";
echo "abs is= " . $_SESSION["abc"]; // should echo 123 once the page is reloaded
$_SESSION["abc"] = 123;
echo session_start(); //returns true if session was succefully started/resumed
echo "";
echo "abs is= " . $_SESSION["abc"]; // should echo 123 once the page is reloaded
$_SESSION["abc"] = 123;
if you mean this:
<?php
session_start();
echo "<BR />";
echo "abs is= " . $_SESSION["abc"];
$_SESSION["abc"] = 123;
?>
you will get returned "123" once you reload the page.
* first time you will get an error, because the session variable $_SESSION["abc"] doesn't exist, you need to have a better error handling here.
and change:
echo session_start();
to:
session_start();
<?php
session_start();
echo "<BR />";
echo "abs is= " . $_SESSION["abc"];
$_SESSION["abc"] = 123;
?>
you will get returned "123" once you reload the page.
* first time you will get an error, because the session variable $_SESSION["abc"] doesn't exist, you need to have a better error handling here.
and change:
echo session_start();
to:
session_start();
so this is better:
<?php
echo session_start();
echo "<BR />";
echo "abs is= " . (isset($_SESSION["abc"])?$ _SESSION[" abc"]:"");
$_SESSION["abc"] = 123;
?>
<?php
echo session_start();
echo "<BR />";
echo "abs is= " . (isset($_SESSION["abc"])?$
$_SESSION["abc"] = 123;
?>
ASKER
i tired both but still the same result
my problem is that i had a working code using sessions.
then a few hours ago it just stopped working
i also tried restarting apache with no luck
my problem is that i had a working code using sessions.
then a few hours ago it just stopped working
i also tried restarting apache with no luck
works fine with me using IIS...
>>i also tried restarting apache with no luck
what about if you reboot your machine? or did you make any changes on your apache/php settings?
>>i also tried restarting apache with no luck
what about if you reboot your machine? or did you make any changes on your apache/php settings?
ASKER
no i wasnt making any changes.
I'm now going to try to reboot, once i find the button....
I'm now going to try to reboot, once i find the button....
ASKER
and i rebooted with the same results
ASKER
i found something, it only affect my one of my domains
if i runt test.php on another domain on the same server it works fine
if i runt test.php on another domain on the same server it works fine
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window