?
Solved

$_SESSION does not retain variables

Posted on 2009-05-06
11
Medium Priority
?
335 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 54

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 54

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 54

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 54

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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.
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…
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.
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

864 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