Page 1 of 1

Trouble with sessions 2

Posted: Fri Jul 26, 2002 3:51 pm
by Gavski
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

Posted: Fri Jul 26, 2002 4:56 pm
by RandomEngy
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

Code: Select all

$_SESSION&#1111;'per']=$_POST&#1111;'per'];
to

Code: Select all

if( isset($_POST&#1111;'per']) )
  $_SESSION&#1111;'per']=$_POST&#1111;'per'];