473,659 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session Variables dissapears...

2 New Member
Hello i have problem my session variables seem to disapear as i go along i've created this code to ilustrate whats happening

First off i just post 3 detials like a name a age and a favourite number.

that in turn goes to the next page where its being picked up by the php code and put into the Global Variable.

the page uses the variables with no problem and you can select a link to go onto the next page where the number is being reworked using simple maths.

and so it goes on when it comes to the last page it concats all the variables into a single global varible and send back to the 2nd page where it displays the all the numbers. but my posted values dispears at this stage. and if you run the same procedure again it shows the values is nothing and the number value is 0.

Could some one please assist me in helping me retain these values. i think when i load the 2nd page again it creates either a new session ID or just loses the info completely cause the values are being reasigned in that page.

Here is the code....

Start.php
[PHP]

<?php session_start()

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitl ed Document</title>
</head>
<form action="session .php" method="post" name="form1" id="form1">
Enter your name:
<input name="NAME" type="text" />
<br />
Enter your Age:
<input name="AGE" type="text" />
<br />
Enter Your Favourite number:
<input name="NUMBER" type="text" />
<input name="submit" type="submit" value="Submit" />
</form>
<body>
</body>
</html>

[/PHP]

session.php
[PHP]

<?PHP
header("Expires : Thu, 17 May 2001 10:17:17 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0

session_start() ;

$_SESSION['Begin']= "here";
$_SESSION['Mid']= "we go";
$_SESSION['End']= "again";

$_SESSION['NUM']= $_POST['NUMBER']; // these are the values that gets lost the second round.
$_SESSION['NAME']= $_POST['NAME']; // these are the values that gets lost the second round.
$_SESSION['AGE']= $_POST['AGE']; // these are the values that gets lost the second round.

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sessio n testing</title>
</head>

<body>
<?php echo 'Hello '.$_SESSION['NAME'].' how are you? i see you are '.$_SESSION['AGE']; ?>
<br />
<a href="page1.php ">Page1.php </a>
<br />
<div align="center">
<?php echo $_SESSION['total']; ?>
<br />
<br />
<?php echo $_SESSION['CHANGES']; ?>
</div>


</body>
</html>

[/PHP]

Page1.php
[PHP]

<?PHP
header("Expires : Thu, 17 May 2001 10:17:17 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0

session_start() ;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sessio n testing</title>
</head>

<body>
<p><?php echo $_SESSION['Begin']; ?>
<br />
<a href="page2.php ">Page2.php </a></p>
<?php $_SESSION['PAGE1'] = ($_SESSION['NUM'] / 2); ?>

</body>
</html>

[/PHP]

Page2.php

[PHP]

<?PHP
header("Expires : Thu, 17 May 2001 10:17:17 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0

session_start() ;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sessio n testing</title>
</head>

<body>
<?php echo $_SESSION['Begin']; ?>
<br />
<?php echo $_SESSION['Mid']; ?>
<br />
<?php echo $_SESSION['PAGE1']; ?>
<br />
<a href="page3.php ">Page3.php </a>
<?php $_SESSION['PAGE2'] = ($_SESSION['NUM'] + 2); ?>
</body>
</html>

[/PHP]

Page3.php

[PHP]

<?PHP
header("Expires : Thu, 17 May 2001 10:17:17 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0

session_start() ;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sessio n testing</title>
</head>

<body>
<?php echo $_SESSION['Begin']; ?>
<br />
<?php echo $_SESSION['Mid']; ?>
<br />
<?php echo $_SESSION['End']; ?>
<br />
<?php echo $_SESSION['PAGE1']; ?>
<br />
<?php echo $_SESSION['PAGE2']; ?>
<br />
<?php $_SESSION['total']= $_SESSION['Begin'].' '.$_SESSION['Mid'].' '.$_SESSION['End']; ?>
<br />
<a href="Session.p hp">Session.php </a>
<?php $_SESSION['PAGE3'] = ($_SESSION['NUM'] * 9); ?>
<?php $_SESSION['CHANGES'] = $_SESSION['PAGE1'].' '.$_SESSION['PAGE2'].' '.$_SESSION['PAGE3']; ?>
</body>
</html>

[/PHP]

I'm a complete noob to PHP and i'm trying to play around with the sessions to be able to apply them later.

Thanks
Mar 4 '07 #1
0 1473

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2385
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an email from (possibly) three seperate forms. the following code is the end of a routine which stashes data from the first form off to session variables and then redirects itself to the proper form / procedure depending upon the state of two...
10
3500
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much more time I have on a session? If I do a refresh, does reset the session clock? Do you have have to go to another page to reset the session timeout or will a postback also do it? This is important as we have a few pages that a user
4
15208
by: Aidas Pasilis | last post by:
I'm saving some values to the Session state and get some strange results. To be short I'll write example code and standart behavior: Code Example: ///////////////////////////////////////////////////////////////////////////////////////// private void WriteToSessionButton_Click(object sender, , System.EventArgs e) { Session = "My value";
6
1276
by: Dirc Khan-Evans | last post by:
I have a problem with a Session variable that dissapears after a postback of one of my pages. This only happens on WIn 2003 servers.. it is fine on my XP dev box. This page opens in another window, but I have ascertained that is is definitely using the same session ID. Nowhere on the page do I clear the session variable.. it is only ever retrieved... this page only works if it is there.
3
2903
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have any experience on how to keep track of session value. Any help it's appreciated. Thanks Alan
18
3432
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that File-New-Window creates an instance of IE in the same process with the same SessionID as the parent window is in big trouble. This fundamentally restricts the usefullness of using session state management. I probably missed it somewhere - can...
26
3596
by: BillE | last post by:
Some ASP.NET applications use Session Variables extensively to maintain state. These should be re-written to use viewstate, hidden fields, querystring, etc. instead. This is because if a user opens a new IE window with Ctrl-N or File-New-Window, BOTH WINDOWS SHARE THE SAME SESSION VARIABLES. This cannot be prevented.
7
1572
by: dangerd | last post by:
Hello, Thought I'd try this forum as I got some useful help from here before. Anyway, this is the problem; I have a simple authorisation script (in PHP): www.multidome.co.uk/test/authorisation.txt It works great locally but when I upload it no longer works well; the
9
1246
by: =?Utf-8?B?TmVkaW0=?= | last post by:
I have a asp.net 2/c# web database application which works fine, but ocassionaly sesion data just dissapears. It's not any timeout as it happens in the middle of work on it, and I just get 2 possible erros - obj ref not set... cause the object in sesion no longers exists or it forwards users to the log on page. as it happens frequently during the work it became a very big problem, and I have no idea what could cause it. pls help :)
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8339
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8535
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8629
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.