Solved

$_SESSION does not retain variables

Posted on 2009-05-06
11
320 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 50

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 50

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 50

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
 
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 50

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

813 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

17 Experts available now in Live!

Get 1:1 Help Now