Solved

Modifying PHP session variables

Posted on 2002-07-24
3
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 200 total points
ID: 7176680
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

717 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