Link to home
Start Free TrialLog in
Avatar of ipc
ipc

asked on

Modifying PHP session variables

Hello all,


I am having a little trouble modifying PHP session variables and was hoping the community could shed some light. My objective is to have a 3 part form with several variables registered is a session per page. Registering the sessions works fine, however if the user hits the back button they are unable to modify the value of the variable. Here is the code snippet:

The form:
<?php
Header('Cache-Control: no-cache');
Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
Header('Pragma: no-cache');

     session_start();
     
     if (!$PHPSESSID)
     {
          session_register('var');
          session_register('var2');
     }
?>

<form method="POST" action="test2.php?<?php echo ("$PHPSESSID"); ?>">
  <p>
  VAR 1&nbsp;&nbsp;&nbsp;
  <select size="1" name="var">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  </select></p>
  <p>VAR 2&nbsp;&nbsp;&nbsp;
  <select size="1" name="var2">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  </select></p>
  <p>&nbsp;</p>
  <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>



And the "POSTED" to page:

<?
Header('Cache-Control: no-cache');
Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
Header('Pragma: no-cache');
     
     session_start();

     if (!$PHPSESSID)
     {
          session_register('var');
          session_register('var2');
     }


     echo ("varone=$var<br>");
     echo ("vartwo=$var2<br>");
?>



Any help would be appreciated.


Thanks
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial