Solved

$_SESSION does not retain variables

Posted on 2009-05-06
11
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 51

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 51

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 51

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 51

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
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 dynamically set the form action using jQuery.

726 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