Solved

Modifying PHP session variables

Posted on 2002-07-24
3
187 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:ipc
3 Comments
 
LVL 40

Accepted Solution

by:
RQuadling earned 200 total points
Comment Utility
Something that MAY be useful is to add a timestamp as a query on the action ...

<script language="JavaScript"><!--
document.writeln('<form method="POST" action="test2.php?<?php echo ("$PHPSESSID"); ?>&ts=' + date.UTC() .'">');
//--></script>



I think that is right!

Basically you are using the client to add another unique parameters which, in most cases, will cause the URL to be different which should force a resend the request properly, rather than relying on some cached value.

Richard.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now