session do's not seem to be working

ive set the session variable . But when i try to access it from the next page i get nothing sometimes it prints the number one when i click refresh
perrierileyAsked:
Who is Participating?
 
nizsmoConnect With a Mentor DeveloperCommented:
This simple example should work, and is the correct way to access and assign session variables:
####page1.php####
<?php
session_start();
$testvalue = "myvalue";
$_SESSION["mysession"] = $testvalue;
?>
#################
 
 
####page2.php####
<?php
session_start();
 
// This should echo 'myvalue'
echo $_SESSION["mysession"];
?>

Open in new window

0
 
nizsmoDeveloperCommented:
Do you have:

session_start();

on top of the second page where you want to access the session variable?
0
 
perrierileyAuthor Commented:
yes i do have session_start(), i tried with single qoutes double qoutes it works sometimes, sometimes it does  not. if i click refresh the echo value clears or displays 1.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Ashish PatelCommented:
if you have IIS server, then check the properties of all Application pools and check in  performance tab that maximum number of worker processes is set to 1.
0
 
perrierileyAuthor Commented:
im using a linux server with php 4
0
 
Ashish PatelCommented:
okay but you should be having some web server installed, which one is that?
0
 
perrierileyAuthor Commented:
apache
0
 
Ashish PatelCommented:
So you will have to check in the web server configuration as what is set for StartServer directive.
check the site link for more help about how to go for StartServer. And on the right hand of the link page there is a link on StartServer, please click it and see how to set it.
http://httpd.apache.org/docs/2.0/mod/worker.html
0
 
nizsmoDeveloperCommented:
Do a:

<?php phpinfo(); ?>

and make sure your session is enabled. You should see something like this:

session
Session Support       enabled
Registered save handlers       files user sqlite
Registered serializer handlers       php php_binary wddx
0
 
nizsmoDeveloperCommented:
Also are you able to show us the example which you are trying? The example I gave in the second post didn't work?
0
 
perrierileyAuthor Commented:
the declaration example nizsmo  showed me above is the way i was doing it.. its passing the session in the variable to the next page but when i refresh the page, the variable in the session resets to 1. The server setting  are exactly as you said
except for the wddx..

session
Session Support       enabled
Registered save handlers       files user sqlite
Registered serializer handlers       php php_binary  EXCEPT FOR THIS -> wddx
0
 
nizsmoDeveloperCommented:
>>but when i refresh the page, the variable in the session resets to 1

When you refresh which page? Looks like your session variables are and should be working fine.
0
 
simonkinCommented:
Add this to yout pages so we can see the output....
<?php
 
 
?>

Open in new window

0
 
simonkinConnect With a Mentor Commented:
Sorry....
<?php
 
     // Outputs the session array
     print_r($_SESSION);
 
?>

Open in new window

0
 
perrierileyAuthor Commented:
the session print_r outputs this Array ( [user_id] => 1 [userid] => 1 ) 1 on the second page
on the page where the session is initialize the array looks like this Array ( [user_id] =>48 [userid] => 1 )
and i have no idea where the userid variable is coming from the user_id is the one iam initializing..
0
 
perrierileyAuthor Commented:
after i close the browser and open a new one start over again (login and go through the process) the variable passes to the second page. but if i refresh the second page the array value thats displaying will reset to 1..(session is initialized on the first page $user_id )
0
 
perrierileyAuthor Commented:
thank you guys
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.