Zend - The PHP Company




HTTP

Add Code


Post as Get Method  

Type: code fragment
Added by: crackbaby
Entered: 01/06/2000
Last modified: 08/12/1999
Rating: ***** (4 votes)
Views: 8470
Use this code to make a Post method act like a Get method.


<?
/*
   [Post acting like a Get method]
   This code will take <all> varables sent via a form <POST> method and
   store them in a session variable so that when you hit the back button
   in the browser you will be able to repopulate the form. Using this will
   make it possible to never use a get method and to never get the "DATA        
   NOT found" errors in a browser.
   All variable names can be used just like in a get/post method as well.

   $rdX => a variable that is passed into the form
   $tmp_query => temp session variable to store query data
    -crkBbyX 2000-05-31
*/
session_begin();
if(
$rd == '1') {
   
$tmp_query '';
   foreach (
$HTTP_POST_VARS as $key => $value) {
       
$tmp_query .= $key "=" $value "&";
   }
   
session_register("tmp_query"); 
   
header("Location: http://$SERVER_NAME/<thisfile>?rd=0");
   exit;
} else {
  if(isset(
$tmp_query)) {
    
parse_str($tmp_query);
  }
}

/*
  PHP: [Starting a session]
          $sess_sessname => what the session name will be
*/
  
function session_begin() {
     global 
$sess_sessname;
     if(!isset(
$sess_sessname)) { $sess_sessname 'SESSION_ID'; }
     
session_name("$sess_sessname");
     
session_start();
     unset(
$sess_sessname);
  }
?>


Usage Example


I will update this soon with an example url and all source code.


Rate This Script





Search



This Category All Categories