Solved

$_SESSION does not retain variables

Posted on 2009-05-06
11
317 Views
Last Modified: 2012-05-06
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.
0
Comment
Question by:CMDAI
  • 7
  • 4
11 Comments
 
LVL 1

Author Comment

by:CMDAI
ID: 24312549

<?php

echo session_start();

echo "<BR />";

echo "abs is= " . $_SESSION["abc"];

$_SESSION["abc"] = 123;

?>
 

==RESULT==

1

abs is=

Open in new window

0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 24312613
huh?

you mean this????


<?php
session_start();

$_SESSION["abc"] = 123;

echo "<BR />";
echo "abs is= " . $_SESSION["abc"];

?>
0
 
LVL 1

Author Comment

by:CMDAI
ID: 24312639
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;  
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 24312660
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();
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 24312681
so this is better:

<?php
echo session_start();
echo "<BR />";
echo "abs is= " . (isset($_SESSION["abc"])?$_SESSION["abc"]:"");
$_SESSION["abc"] = 123;
?>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:CMDAI
ID: 24312705
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
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 24312721
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?
0
 
LVL 1

Author Comment

by:CMDAI
ID: 24312854
no i wasnt making any changes.
I'm now going to try to reboot, once i find the button....
0
 
LVL 1

Author Comment

by:CMDAI
ID: 24312916
and i rebooted with the same results
0
 
LVL 1

Author Comment

by:CMDAI
ID: 24312977
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
0
 
LVL 1

Accepted Solution

by:
CMDAI earned 0 total points
ID: 24313020
OK i got it to work,
I have no idea why even restarting server didn't help
but when i switched off appache module for this domain, and switched it back on, it started to work
....in mystery i will remain....
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now