Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

session do's not seem to be working

Posted on 2007-11-27
17
Medium Priority
?
297 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
[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
  • 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 1000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
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…

715 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