I want to post a variable to a page and for that page to make it a session variable like so-
<?php
session_start();
$_SESSION['per']=$_POST['per'];
echo $_SESSION['per'];
?>
(The variable per is posted from another page.)
this echo's the variable 'per' but not when the page is returned to, so the post is successful but the variable will not persist??
Anyone help on this??
thanks
Gav
Trouble with sessions 2
Moderator: General Moderators
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
When you return to the page, there is no longer a $_POST['per'] . So when you do $_SESSION['per']=$_POST['per']; you are updating $_SESSION['per'] to a null value, thus it will not echo when you return to the page.
To fix this, change
to
To fix this, change
Code: Select all
$_SESSIONї'per']=$_POSTї'per'];Code: Select all
if( isset($_POSTї'per']) )
$_SESSIONї'per']=$_POSTї'per'];