473,508 Members | 2,303 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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled 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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Session 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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Session 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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Session 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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Session 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.php">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 1468

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

Similar topics

6
2366
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...
10
3478
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...
4
15146
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:...
6
1271
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...
3
2890
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...
18
3401
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...
26
3577
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...
7
1565
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): ...
9
1239
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...
0
7224
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,...
0
7120
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...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7039
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...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
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 ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.