How about: <?php if($_POST['submit'] && !isset($_SESSION['read'])){ //Then the post has been submitted $pinvalue = false; $pinFound = false; $get = $_POST["value"]; if($get){ //Then a pin was entered $empty = false; $dir = opendir("pin"); while($read = readdir($dir)){ if($read == $get){ //The pin was found $pinFound = true; $_SESSION['read'] = $read; } } if(!$pinFound){ //The pin was not found echo "<div id=\"center\">ERROR: The pin was not found. You submitted a pin with the value: $get </div>"; unset($_SESSION['read']); } closedir($dir); } else{ //A pin was not entered $empty = true; echo "Sorry you did not enter a pin"; } } elseif(!isset($_SESSION['read'])){ //The form hasn't been submitted and a session does not exist so display form ?> <div id=center> <p>PIN <br> <form method="post"> <input type="text" id="pinfield" name="value"> <input type="submit" class="pinbutton" value="Add" name="submit"> </form> </p> </div> <?php } //Now let's check if the session 'read' exists if(isset($_SESSION['read'])){ //Then the user has already entered in a correct pin ?> <form action="<?php echo $obj->self.''.rand(1000,9999);?>" method="post"> Enter link: <br> <input type="text" size="40" name="url" value="<?php if (isset($_REQUEST['url'])) echo $_REQUEST['url']; ?>"/> <input type='submit' value='Click'/> </form> <?php } ?> PHP:
Make sure you have session_start(); at the very top of your document as otherwise it will not work. What the code does is: 1. It will display the PIN form if it has not been submitted, or the session variable 'read' hasn't been set 2. If the pin form has been submitted it will check to see if the exists and create the session variable 'read' if it does, if not then it outputs an error. 3. It will display the other form and not the pin form if the session value 'read' has been set.