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