Solved

$_SESSION does not retain variables

Posted on 2009-05-06
11
314 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
Comment Utility

<?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
Comment Utility
huh?

you mean this????


<?php
session_start();

$_SESSION["abc"] = 123;

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

?>
0
 
LVL 1

Author Comment

by:CMDAI
Comment Utility
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
Comment Utility
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
Comment Utility
so this is better:

<?php
echo session_start();
echo "<BR />";
echo "abs is= " . (isset($_SESSION["abc"])?$_SESSION["abc"]:"");
$_SESSION["abc"] = 123;
?>
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:CMDAI
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
and i rebooted with the same results
0
 
LVL 1

Author Comment

by:CMDAI
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 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

9 Experts available now in Live!

Get 1:1 Help Now