I have 3 pages
page1.php
<?
session_start() ;
session_register("value") ;
$value = 1
?>
page2.php
<?
session_start() ;
$value++ ;
?>
page3.php
<form method="POST" action="page1.php">
<?
session_start() ;
$value++ ;
?>
<input type="submit" value="Submit" name="B1">
</form>
I would like I can preserve value of $value now is 3 when I come back to page1.php from page3.php , when I come back page1.php value of $value is now set to 1, please help me , thanks
How to preserve value ?
Moderator: General Moderators
page1.php
Code: Select all
<?php
session_start() ;
// This will stop the value being recreated if it already exists.
if(!session_is_registered("value"))
{
session_register("value");
$value = 1;
}
?>Just a small tip:
Lookup session_register in the man (tho you'll learn that you wont need it) and read up. Using $_SESSION is, imho, more simplified (not just regarding you problem)...The Manual wrote: Caution:
If you want your script to work regardless of register_globals, you need to use the $_SESSION array. All $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where register_globals is disabled.
Code: Select all
<?php
if (!isset($_SESSION['value'])) {
...code...
}
?>