Solved

session do's not seem to be working

Posted on 2007-11-27
17
263 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

920 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

11 Experts available now in Live!

Get 1:1 Help Now