Created
January 6, 2012 02:23
-
-
Save shamess/1568621 to your computer and use it in GitHub Desktop.
An interpretation of the PRG pattern, using PHP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does this line
do? And how do we fetch the actual posted data?