Solved

session do's not seem to be working

Posted on 2007-11-27
17
274 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:perrieriley
  • 7
  • 5
  • 3
  • +1
17 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20363050
Do you have:

session_start();

on top of the second page where you want to access the session variable?
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 250 total points
ID: 20363072
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
 

Author Comment

by:perrieriley
ID: 20363246
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20363275
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
 

Author Comment

by:perrieriley
ID: 20363290
im using a linux server with php 4
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20363296
okay but you should be having some web server installed, which one is that?
0
 

Author Comment

by:perrieriley
ID: 20363302
apache
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20363315
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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20363644
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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20363652
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
 

Author Comment

by:perrieriley
ID: 20363775
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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20363787
>>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
 
LVL 4

Expert Comment

by:simonkin
ID: 20364503
Add this to yout pages so we can see the output....
<?php
 
 
?>

Open in new window

0
 
LVL 4

Assisted Solution

by:simonkin
simonkin earned 250 total points
ID: 20364517
Sorry....
<?php
 
     // Outputs the session array
     print_r($_SESSION);
 
?>

Open in new window

0
 

Author Comment

by:perrieriley
ID: 20366450
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
 

Author Comment

by:perrieriley
ID: 20366512
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
 

Author Closing Comment

by:perrieriley
ID: 31411351
thank you guys
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to count occurrences of each item in an array.
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…

773 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