473,379 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Why does a session variable return to its old value?

I have a problem in my application I have not been able to reproduce
completely with a simpler set of files. I know this is a crime, but
here goes:

In a file I have these instructions:

echo 'before: '.$_SESSION['classtitle'].'<br />';
require_once 'test3.php';
echo 'after: '.$_SESSION['classtitle'].'<br />';
echo '<p><a href="test.php">test</a></p>';

They display on the screen:

before: b
test3 before: b
test3 after: a
after: a

So far, so good. But, when I click the link to test.php, this is
displayed:

test: b

I don't understand how $_SESSION['classtitle'] goes back to its old
value.

Here are test3.php and test.php:

test3.php:
<?php
session_start();
echo 'test3 before: '.$_SESSION['classtitle'].'<br />';
$_SESSION['classtitle'] = 'a';
echo 'test3 after: '.$_SESSION['classtitle'].'<br />';
?>

<?php
session_start();
echo 'test: '.$_SESSION['classtitle'].'<br />';
?>

Can anyone point me in the right direction, please?

Regards,

Jan Nordgreen

Jun 13 '07 #1
5 3584
I have just discovered that the problem can be simplified a bit;
test3.php is not needed.

$_SESSION['classtitle'] = 'b';
echo 'main: '.$_SESSION['classtitle'].'<br />';
unset($_SESSION['classtitle']);
echo '<p><a href="test.php">test</a></p>';

This displays:

main: b

But when I click the link to test.php I get:

test: a

Conclusion: $_SESSION['classtitle'] in test.php is not the same as in
the main program. How come?

Regards,

Jan Nordgreen
Jun 13 '07 #2
damezumari wrote:
I have just discovered that the problem can be simplified a bit;
test3.php is not needed.

$_SESSION['classtitle'] = 'b';
echo 'main: '.$_SESSION['classtitle'].'<br />';
unset($_SESSION['classtitle']);
echo '<p><a href="test.php">test</a></p>';

This displays:

main: b

But when I click the link to test.php I get:

test: a

Conclusion: $_SESSION['classtitle'] in test.php is not the same as in
the main program. How come?

Regards,

Jan Nordgreen

Are you calling session_start() at the top of the page that links to
test.php?

Robin
Jun 13 '07 #3
Yes, I do.

Jun 13 '07 #4
damezumari wrote:
I have just discovered that the problem can be simplified a bit;
test3.php is not needed.

$_SESSION['classtitle'] = 'b';
echo 'main: '.$_SESSION['classtitle'].'<br />';
unset($_SESSION['classtitle']);
echo '<p><a href="test.php">test</a></p>';

This displays:

main: b

But when I click the link to test.php I get:

test: a

Conclusion: $_SESSION['classtitle'] in test.php is not the same as in
the main program. How come?

Regards,

Jan Nordgreen
Hi,

This shouldn't happen.
You unset that sessionvar, so it should be gone on test.php, and thus
produce an error.
You *DO* have errorreporting on I hope?
If unsure, inspect your php.ini, or put this above all your files:
error_reporting(E_ALL);

If that doesn't enlighten you in any way: Why don't you post both files here
so we can inspect them?
(Preferably your simplified versions)

Regards,
Erwin Moller
Jun 13 '07 #5
Yes, error checking is on in php.ini.

I have found my error:

Further down in the main program I had a new assignment to
$_SESSION['classtitle']:

$_SESSION['classtitle'] = 'b';
echo 'main: '.$_SESSION['classtitle'].'<br />';
unset($_SESSION['classtitle']);
echo '<p><a href="test.php">test</a></p>';
...
...
...
$_SESSION['classtitle'] = a;

It is of course the last assignment to $_SESSION['classtitle'] in the
main program that is in effect when the user clicks the link to
test.php, not the last assignment before the link.

Silly me! :)

Thanks for the responses!

Regards,

Jan Nordgreen

Jun 13 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martien van Wanrooij | last post by:
Some time ago I already posted a question about a site that consists of several pages where the visitor, on every page can answer one or two questions in order to fill out an intake for for an...
6
by: -D- | last post by:
I'm trying to accomplish the following. I'm trying to get the values for the table rows that are dynamically created to persist through a redirect. Referring URL:...
2
by: Gavin Lyons via .NET 247 | last post by:
Hello, I'm writing a newsletter application which uses backgroundthreading. I'm using Session variable to report on progresswhile it loops through a dataset. The 'Status.aspx' pagerefreshes every...
4
by: antonyliu2002 | last post by:
I have the following simple code to test if my session is working: <Script Runat="Server"> Sub LinkButtonGenInfo_Click(s As Object, e As EventArgs) If txtFirstName.Text <> Nothing Then...
14
by: Coleen | last post by:
Hi All :-) We have an APSX application using VB.net as the code behind, which uses one or two session variables per page. These Session variables are passed to the final page and calculations...
2
by: puja | last post by:
hi all, I have a problem. I have a class file name Agent which has Name and SalesPerson as two strings. On below page, am reading session object called agentdetail of class Agent and filling out...
6
by: amjad | last post by:
hi i store some value in session object and later try to access it but the value return from session variable is null like Session=txtmyname.Text; Session=txtAge.Text;...
4
by: Don Miller | last post by:
I am using a Session variable to hold a class object between ASP.NET pages (in VB). In my constructor I check to see if the Session variable exists, and if it doesn't, I create one and populate it...
17
by: Control Freq | last post by:
Hi, Not sure if this is the right NG for this, but, is there a convention for the variable names of a Session variable? I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.