Solved

Modifying PHP session variables

Posted on 2002-07-24
3
192 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use 2 ON statements in inner join 3 44
How can I split a variable 19 45
PHP and accessing Array Elements 3 34
replacate wordpress websites 3 23
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

734 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