How do I maintain the $post value when a page is refreshed; In other words how do I refresh the page without losing the Post value
When you need to set a variable that should be reflected in the next page(s), use: var someVarName = "value"; localStorage. setItem("someVarKey", someVarName);
a) If you submitted a form, performing a POST and then hit refresh, the browser will do another POST. b) If you just clicked a link that took you to another page, performing a GET, you'll a refresh will perform a get.
For example, if you are on a web page, refreshing the page displays the most recent content published on that page. Essentially, you're asking the site to send your computer the newest version of the page you're viewing. 2. The refresh button, also known as the refresh option, is a function of all Internet browsers.
This in not possible without a page submit in the first place! Unless you somehow submitted the form fields back to the server i.e. Without Page Refresh using jQuery etc. Somesort of Auto Save Form script.
If this is for validation checks no need for sessions as suggested.
User fills in the form and submits back to self Sever side validation fails
$_GET
<input type="hidden" name="first"
value="<?php echo htmlspecialchars($first, ENT_QUOTES); ?>" />
validation message, end.
alternatively as suggested save the whole post in a session, something like this, but again has to be first submitted to work....
$_POST
if(isset($_POST) & count($_POST)) { $_SESSION['post'] = $_POST; }
if(isset($_SESSION['post']) && count($_SESSION['post'])) { $_POST = $_SESSION['post']; }
You can't do this. POST variables may not be re-sent, if they are, the browser usually does this when the user refreshes the page.
The POST variable will never be re-set if the user clicks a link to another page instead of refreshing.
If $post
is a normal variable, then it will never be saved.
If you need to save something, you need to use cookies. $_SESSION
is an implementation of cookies. Cookies are data that is stored on the user's browser, and are re-sent with every request.
Reference: http://php.net/manual/en/reserved.variables.session.php
The $_SESSION variable is just an associative array, so to use it, simply do something like:
$_SESSION['foo'] = $bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With