Skip to content

Instantly share code, notes, and snippets.

@tanakahisateru
Created May 12, 2011 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanakahisateru/968281 to your computer and use it in GitHub Desktop.
Save tanakahisateru/968281 to your computer and use it in GitHub Desktop.
Request continuation for confirmation page
<?php
/**
* Request continuation
*
* This utility provides a very short lifetime (and navigation closed) session.
* Confirmation page shown after user input form should hold previously poted
* data and passes them to the next request. Those data would live in only two
* requests, so they should be in request scope.
* It's bad idea to use cookie or _SESSION to implement for confirmation page!
*
* CONFIRMATION PAGE:
* <input type="hidden"
* name="encoded_prev_post"
* value="<?php echo htmlspecialchars(RequestContinuation::encode($_POST));?>" />
* <input type="submit" value="commit" />
*
* COMMIT/MODIFY ACTION:
* $prev_post = RequestContinuation::decode($_POST['encoded_prev_post']);
*
*/
class RequestContinuation {
/**
* @param $data array
* @return string
*/
public static function encode($data) {
return http_build_query($data);
}
/**
* @param $data string
* @return array
*/
public static function decode($data) {
parse_str($data, $buf);
return $buf;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment