Solved

Can't retrieve Session Variables on second page

Posted on 2003-11-23
8
412 Views
Last Modified: 2013-12-13
I'm registering some session variabels after successful login, but when i try to retrieve those session variables on second page, it gives me empty values.

However i tested session variables on same page of loginscript. It shows me the results, but no response on another page.

What's the solution??
0
Comment
Question by:akilwani
8 Comments
 
LVL 1

Expert Comment

by:show_source
Comment Utility
You should show the code you are using, then it would be eaiser to help.

but this should work, if session.save_path is correct defined in php.ini

page1.php:

<?php
session_start();

$_SESSION["test"] = "Just a test";
echo $_SESSION["test"];
?>
<p>

<a href="page2.php">Page 2</a>

page2.php

<?php
session_start();

echo $_SESSION["test"];
?>
<p>

<a href="page1.php">Page 1</a>
0
 

Author Comment

by:akilwani
Comment Utility
i've set the session.save_path to C:/Windows/Temp in php.ini. I checked the temp, its saving the session variables. But its strange that i can't retreive the session variables in inner pages.

Also I tested your simple script....I can't retrieve session variable on page2.....

0
 
LVL 4

Expert Comment

by:duerra
Comment Utility
Greetings,
Make sure you are calling session_start() at the top of every page.  If it is not called on every single page that you are using PHP session variables, you will not have access to them.

Hope that helps
~duerra
0
How to run any project with ease

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

 

Author Comment

by:akilwani
Comment Utility
Actually the problem was in PHP.INI file...i extended the session time and now session variables are working fine.
0
 
LVL 4

Expert Comment

by:duerra
Comment Utility
=)

Glad you figured it out.  You can get your points refunded from the Community Support area.  Just post this link in there and tell them that you found your answer.
0
 
LVL 4

Expert Comment

by:duerra
Comment Utility
He found his answer.  No objections.
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
Comment Utility
PAQed, with points refunded (50)

Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

How to run any project with ease

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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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 dynamically set the form action using jQuery.
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…

743 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