Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An interpretation of the PRG pattern, using PHP.
session_start ();
if ($_POST['some_text']) {
$_SESSION['some_text'] = $_POST['some_text'];
header ('HTTP/1.1 303 See Other');
header ('Location: ./');
} else {
$some_text = "<p>No text set yet.</p>\n";
if ($_SESSION['some_text']) $some_text = "<p>'some_text' has been set to '".$_SESSION['some_text']."'.</p>\n";
<!DOCTYPE html>
<title>PRG in PHP</title>
<p>See <a href="">my blog</a> for more information.</p>
<?php echo $some_text; ?>
<form method="POST" action="">
<p>This is a form, that will submit data back to this page using POST.</p>
<p>Enter a value for $_POST['some_text']: <input type="text" name="some_text" /></p>
<p><input type="submit" /></p>

This comment has been minimized.

Copy link

@sannidhyashukla sannidhyashukla commented Mar 4, 2013

What does this line

header ('Location: ./');

do? And how do we fetch the actual posted data?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.