Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An interpretation of the PRG pattern, using PHP.
<?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>
<html>
<head>
<title>PRG in PHP</title>
</head>
<body>
<p>See <a href="http://blog.shamess.info/2012/01/06/postrequestget-pattern-in-php/">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>
</form>
</body>
</html>
@sannidhyashukla

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