Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP $_POST strange behavior, only works 2nd time form is posted
    text
    copied!<p>I'm genuinely stuck on something VERY irritating. After a couple of hours of trying everything I know I've ended up here to see if anyone can help. Here's the general idea. </p> <p>I want one certain page to be available with a password sent via a form. There is no user, and the password will not change. This should be easy, right!</p> <p>I've got a form which submits with the method set to post, and the action set to <code>$_SERVER['PHP_SELF']</code>. The plan is, when the password variable I've pre-defined matches what is typed in the form, one set of content shows on the page, when it doesn't you get a different set of content (a form). </p> <p>Here's what's weird. When looking at a <code>print_r</code> I see whatever I submit in the form in the array, but when I put the right password in the array fills, then empties quickly. I see this on the page reload. It completely empties itself. Even stranger, the 2nd time I do this, it works. What am I missing here? I'd love to know!</p> <p>Many thanks, and Merry Christmas. </p> <p>---- some code ----</p> <p>The form</p> <pre><code> &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt; &lt;label for="pass" id="pass"&gt;Password:&lt;/label&gt; &lt;input type="text" name="pass" id="pass" /&gt; &lt;input type="submit" name="submit" value="Yes" /&gt; &lt;/form&gt; </code></pre> <p>Some PHP from the top of the file;</p> <pre><code>$pass = '12846565488374'; if($_POST['pass']){ $login = $_POST['pass']; } else { $login = 'empty'; } if($login != $pass) { $show = 0; } elseif($login == $pass){ $show = 1; } </code></pre> <p>----- solved ------</p> <p>Turns out this was a JS plugin reloading the page without me knowing. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload