Solved

session do's not seem to be working

Posted on 2007-11-27
17
248 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
im using a linux server with php 4
0
 
LVL 23

Expert Comment

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

Author Comment

by:perrieriley
Comment Utility
apache
0
 
LVL 23

Expert Comment

by:Ashish Patel
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 21

Expert Comment

by:nizsmo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
Sorry....
<?php
 

     // Outputs the session array

     print_r($_SESSION);
 

?>

Open in new window

0
 

Author Comment

by:perrieriley
Comment Utility
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
Comment Utility
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
Comment Utility
thank you guys
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 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