<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1042384" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1042384</link>
    <description></description>
    <language>en</language>
          <item>
    <title>Welcome To The best Online</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/posting-php-self-stop-dublicate-insert-refresh#comment-1286416</link>
    <description> &lt;p&gt;Welcome To The best Online Articles Blog&lt;/p&gt;
 </description>
     <pubDate>Tue, 06 Aug 2013 06:19:29 +0000</pubDate>
 <dc:creator>MARIAFlorova</dc:creator>
 <guid isPermaLink="false">comment 1286416 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Welcome To The best Online</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/posting-php-self-stop-dublicate-insert-refresh#comment-1286415</link>
    <description> &lt;p&gt;Welcome To The best Online Articles Blog&lt;/p&gt;
 </description>
     <pubDate>Tue, 06 Aug 2013 06:19:17 +0000</pubDate>
 <dc:creator>MARIAFlorova</dc:creator>
 <guid isPermaLink="false">comment 1286415 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>well, you can use three</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/posting-php-self-stop-dublicate-insert-refresh#comment-1235580</link>
    <description> &lt;p&gt;well, you can use three pages, or simply send back to the original page&lt;br /&gt;
The method is simply getting the data from the inputs on a page where you get the data and check it without any html output, so it doesnt cache the page&lt;/p&gt;
&lt;p&gt;I will list how i usually have user input checking, three pages&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;form page&lt;/li&gt;
&lt;li&gt;process page&lt;/li&gt;
&lt;li&gt;results page&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is how I generally handle user inputs. With sanatising/checking their data and sending them back to the form page if there was an issue, else send them to the outcome page.&lt;/p&gt;
&lt;p&gt;form page&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;lt;form method=&amp;quot;post&amp;quot; action=&amp;quot;process_page.php&amp;quot;&amp;gt;&lt;br /&gt;USERNAME:&lt;br /&gt;&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;GO&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;process page&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;session_start&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;];&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$return &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//check if empty, all your sanatisation stuff etc &lt;br /&gt;//(i&#039;ve only included very limited checks for this example)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-----&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//check username&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if (empty(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)){ &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//empty&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;login&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]=&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;empty&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$return &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;yes&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;br /&gt;}elseif (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;strlen&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) &amp;lt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;){ &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//too short&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;login&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]=&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;short&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$return &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;yes&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;br /&gt;}elseif (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;strlen&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) &amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;){ &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//too long&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;login&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]=&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;long&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$return &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;yes&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//if any of the above checks were true, then something is wrong. &lt;br /&gt;//send them back (the session will have already been set with the&lt;br /&gt;//info regarding the issue)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$return &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;== &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;yes&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;){&lt;br /&gt;exit (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;header&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;Location: form_page.php&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//if return was not &quot;yes&quot; then all checks were false&lt;br /&gt;//and the data sent is ok to go through, &lt;br /&gt;//update the db or whatever you want then send to results page&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_query&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;insert into ....&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
as you dont have any sessions set, you need to set one. anything will do, but at this point i determine the db query outcomes and set them to sessions for the outcome page &lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_affected_rows&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;query_a&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) != &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;){&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;logindone&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;querya&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]=&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;error&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;}else{&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;logindone&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;querya&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]=&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;ok&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;exit (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;header&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;Location: results_page.php&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;));&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;results_page&lt;br /&gt;
if session is set then there are results, else they (you) got to the page some other way and cannot use it for anything, or you have already had your results (page refresh / browser back etc)&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;session_start&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if(isset(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;logindone&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;])){&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//if ok&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;logindone&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;querya&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]==&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;ok&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;){&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;the db was successfully updated&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//if errors&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;}elseif(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;logindone&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;querya&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]==&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;error&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;){&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;There was a problem inserting into the db&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;}else{&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;the session is set but is not &#039;ok&#039; or &#039;error&#039; - unexpected result&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//else session is not set&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;}else{&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;to use this page you have to fill out the form on form_page.php&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//unset the session always, &lt;br /&gt;//then the results message can only be done once&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;unset(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;logindone&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;another option..at the return point in the process_page (if $return=&quot;yes&quot;) (before the header redir) you can set another session to remember their inputs if you wish. as they are being sent back, you could set a session such as&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;logindata&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]=&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
That will put in a session whatever was posted (if anything)&lt;br /&gt;
Then in the form have the value .. eg&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;&amp;lt;input type=&quot;text&quot; name=&quot;username&quot;&lt;br /&gt;value=&quot;&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;logindata&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;&quot;&amp;gt;&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;so it sends them back if there was an issue with input and sends the exact error, or continues to the results/outcome page as no checks found any issues&lt;/p&gt;
&lt;p&gt;on the form_page.php, at the top, you use the session set for the errors as so..&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if (isset(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;login&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;])){ &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//is not set then no errors possible&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;login&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]==&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;empty&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;){&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;You did not enter a username&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;br /&gt;}elseif(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;login&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]==&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;long&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;){&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;the username you entered is too long&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;br /&gt;}elseif(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;login&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;username&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]==&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;short&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;){&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;the username you entered is too short&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;//end if isset&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
if you do that, make sure to unset the errors session on the form_page, or they will remain set (and output an error message everytime that page is accessed)&lt;/p&gt;
&lt;p&gt;Obviously that&#039;s all for user input, but you are a user..inputting, so it is the same principal for you and most requirements.&lt;br /&gt;
even the error message will be useful to you when using your own admin CP, so you know what you did wrong..typo or whatever.&lt;/p&gt;
&lt;p&gt;The options are endless but the above is the basics of using session and ideas of sending data back and forth.&lt;br /&gt;
The point is once you have got the POST data and done something with it in a page with no html output, then it wont be cached at all by the browser, as it is all done on the server!&lt;/p&gt;
&lt;p&gt;You can use two pages and send back to the form_page.php&lt;br /&gt;
if session set echo out some results, else echo the form&lt;br /&gt;
or even echo out any results (if session set) AND echo the form below it.&lt;/p&gt;
 </description>
     <pubDate>Wed, 26 Nov 2008 15:29:00 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1235580 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Yes ok thanks for you help.</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/posting-php-self-stop-dublicate-insert-refresh#comment-1235575</link>
    <description> &lt;p&gt;Yes ok thanks for you help.  I have used a separate page.  How can i control then the header output.  If i am including the page, and i have already included the header with HTML i cannot use header(Location).&lt;/p&gt;
 </description>
     <pubDate>Wed, 26 Nov 2008 11:24:20 +0000</pubDate>
 <dc:creator>benf</dc:creator>
 <guid isPermaLink="false">comment 1235575 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Or check for POST</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/posting-php-self-stop-dublicate-insert-refresh#comment-1235552</link>
    <description> &lt;p&gt;Or check for POST data&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;IF &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
or something more specific&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;IF &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;dataname&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;If there is post data the query is already done (show form or whatever), else process the POSTed data.&lt;/p&gt;
&lt;p&gt;But I agree with pr0gr4mm3er, the best way in most circumstances is to have a separate page anyway. Not all requirements makes this approach the best, but usually it allows for easier management as one page is for getting data and the other is for processing it.  This also makes additional options later easier too.&lt;/p&gt;
&lt;p&gt;And my method of doing this is use a $_SESSION, then at the end of the page that inserts to the DB (or whatever) unset the session.&lt;br /&gt;
So if session is set then do whatever, if session is not set give them a message - ie &quot;this page is only used when you fill in a form&quot; etc -&lt;br /&gt;
As they got to the page either some way other than the required means OR they filled in the required form (or whatever) the message will refelct either of these instances.&lt;/p&gt;
&lt;p&gt;Once a form is filled in and submitted, the session is set and goes to the processing and results page, the DB is updated and the session is unset. Thus resolving your problem as refreshing that page will tell them &quot;please use the form on page blah and click submit&quot; (as there is no session set)&lt;/p&gt;
 </description>
     <pubDate>Wed, 26 Nov 2008 01:55:00 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1235552 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>The best way to avoid this</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/posting-php-self-stop-dublicate-insert-refresh#comment-1235544</link>
    <description> &lt;p&gt;The best way to avoid this is to redirect the site visitor to a different page after you process the $_POST data.  So have your script process the form data, and then use header(&#039;Location: some/page.php&#039;) to redirect them to the success page.&lt;/p&gt;
 </description>
     <pubDate>Tue, 25 Nov 2008 20:15:47 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1235544 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
