Problem PIN code access

Discussion in 'PHP' started by newevolution, Jul 13, 2009.

  1. #1
    Problem PIN code access website

    Parse error: syntax error, unexpected T_ELSE in /home/rsgen/public_html/1234.php on line 17

    Please Help:confused:
     
    newevolution, Jul 13, 2009 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here:
    
    if (isset($_SESSION['read'])) {
    else {
    
    PHP:
    You haven't closed the if and your already doing else so should be (even though your if statement is redudant as theres nothing inside it:
    
    if (isset($_SESSION['read'])) {
    }
    else {
    
    PHP:
    This will then throw up another error further down the document. Have a look at this part:

    
    if ($empty)
    } 
    else {
    echo "<div id=center><p>Error PIN</p></div>";
    unset($_SESSION['read']);
    }
    else {
    if ($link == "") {
    
    echo "<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'/>";
    }
    
    PHP:
    1. You are missing an opening curly bracket for your if statement
    2. You are doing if else else, when an if statement should be in the form if(condition){} elseif(condition){} else{} See Here for more info.

    I'm guessing you meant it to be more like this:

    
    if($empty){
    	//Do something here?
    } 
    elseif($link == ""){
    	echo "<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'/>";
    }
    else{
    	echo "<div id=center><p>Error PIN</p></div>";
    	unset($_SESSION['read']);
    }
    
    PHP:
    Although again like earlier your first part is redudant becuase your not actually doing anything inside it.
     
    wd_2k6, Jul 13, 2009 IP
  3. newevolution

    newevolution Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Not working

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
     
    newevolution, Jul 13, 2009 IP
  4. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Again you forgot to close one of your statements:
    
    if (isset($_SESSION['read'])) {
    }
    else {
    echo "<div id=center><p>PIN<br><form method=post><input type=text id=pinfield name=value> <input type=submit class=\"pinbutton\" value=Add></form></p></div>";
    
    PHP:
    should be
    
    if (isset($_SESSION['read'])) {
    }
    else {
    echo "<div id=center><p>PIN<br><form method=post><input type=text id=pinfield name=value> <input type=submit class=\"pinbutton\" value=Add></form></p></div>";
    }
    PHP:
     
    wd_2k6, Jul 13, 2009 IP
  5. newevolution

    newevolution Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Not working

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in on line 22
     
    newevolution, Jul 13, 2009 IP
  6. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Cause you've done if else elseif else
    else is the last clause in an if statement
    im guessing you want to change the elseif to simply an if
     
    wd_2k6, Jul 13, 2009 IP
  7. newevolution

    newevolution Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Can be a bit more clearly?

     
    newevolution, Jul 13, 2009 IP
  8. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Here try:

    if (isset($_SESSION['read'])) {
    }
    else {
    echo "<div id=center><p>PIN<br><form method=post><input type=text id=pinfield name=value> <input type=submit class=\"pinbutton\" value=Add></form></p></div>";
    }
    if($link == ""){
    echo "<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'/>";
    }
    else{
    echo "<div id=center><p>Error PIN</p></div>";
    unset($_SESSION['read']);
    }

    If there's still an error, please post it and copy and paste the line that the line number reffers to.
    Also please explain what you want your script to do as it seems as it could be re-organised.
     
    wd_2k6, Jul 13, 2009 IP
  9. newevolution

    newevolution Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I want to do that person is able to enter the rest of the parties must enter the PIN code

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in on line 23
     
    newevolution, Jul 13, 2009 IP
  10. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Something like:
    
    <?php
    
    $pinvalue = false;
    $get = $_POST["value"];
    
    if($get){
    	$empty = false;
    	$dir = opendir("pin");
    		while($read = readdir($dir)){
    			if($read == $get){
    				$_SESSION['read'] = $read;
    			}//end if
    		}//end while	
    	closedir($dir);
    }//end if 
    else{
    	$empty = true;
    }
    
    
    if(isset($_SESSION['read'])){
    	//?
    }
    else{
    ?>
    	<div id=center>
        	<p>PIN <br>
            <form method="post">
            	<input type="text" id="pinfield" name="value">
                <input type="submit" class="pinbutton" value="Add">
            </form>
            </p>
    	</div>
    <?php
    }
    if($link == ""){
    ?>
    <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
    }
    else{
    	echo "<div id=center><p>Error PIN</p></div>";
    	unset($_SESSION['read']);
    }
    ?> 
    
    PHP:
     
    wd_2k6, Jul 13, 2009 IP
  11. newevolution

    newevolution Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    And what to do in order to cover the field from the Enter link: if you type to be activated ?
     
    newevolution, Jul 13, 2009 IP
  12. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Sorry what do you mean
     
    wd_2k6, Jul 13, 2009 IP
  13. newevolution

    newevolution Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    To not show the Enter link:. Just as a person enters a PIN access
     
    newevolution, Jul 13, 2009 IP
  14. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Something like this:

    
    <?php
    if($_POST['submit']){
    	
    	//Then the post has been submitted
    	$pinvalue = false;
    	$get = $_POST["value"];
    	echo "You submitted a pin with the value: $get <br />";
    
    	if($get){
    		//Then a pin was entered
    		$empty = false;
    		$dir = opendir("pin");
    		while($read = readdir($dir)){
    			if($read == $get){
    				//The pin was found
    				$_SESSION['read'] = $read;
    			}
    			else{
    				//The pin was not found
    				echo "<div id=center><p>Error PIN</p></div>";
    				unset($_SESSION['read']);
    			}
    		}	
    		closedir($dir);
    	} 
    	else{
    		$empty = true;
    		echo "Sorry you did not enter a pin";
    	}
    }
    else{
    	//The form hasn't been submitted so display it
    ?>
    	<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
    }
    
    if(isset($_SESSION['read'])){
    	//Then a valid pin has been entered so display the other form
    ?>
    	<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:
    Which displays the pin box, but if a pin has been submitted then display the enter box ?
     
    wd_2k6, Jul 13, 2009 IP
  15. newevolution

    newevolution Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    But also that if you type the correct PIN code does not show the "You submitted a pin with the value: xxxxx"
     
    newevolution, Jul 13, 2009 IP
  16. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Yup you can delete that line it's here:
    
    echo "You submitted a pin with the value: $get <br />";
    
    PHP:
    I just added it as a test. Or if you want to keep it for when an invalid pin is entered you can move it to the part where it says
    
    //The pin was not found
    
    PHP:
     
    wd_2k6, Jul 13, 2009 IP
  17. newevolution

    newevolution Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    How to do that after you type your PIN and do not save the session after writing the whole time until the closure browser ?
     
    newevolution, Jul 14, 2009 IP
  18. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #18
    What do you mean after the pin has been submitted, then what..
     
    wd_2k6, Jul 14, 2009 IP
  19. newevolution

    newevolution Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    I want to not entered your PIN at all times just until the closure of the browser (something I regard as a session)
     
    newevolution, Jul 14, 2009 IP
  20. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Do you mean, that if somebody has entered a correct pin, then they don't have to enter it again until their session is destroyed? Like this:

    
    
    <?php
    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 
    } 
    elseif(!isset($_SESSION['read']) && $_POST['submit']){
        //Then the post has been submitted 
        $pinvalue = 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
                    $_SESSION['read'] = $read;
                }
                else{
                    //The pin was not found
    				echo "You submitted a pin with the value: $get <br />";
                    echo "<div id=center><p>Error PIN</p></div>";
                    unset($_SESSION['read']);
                }
            }   
            closedir($dir);
        }
        else{
            $empty = true;
            echo "Sorry you did not enter a pin";
        }
    }
    else{
        //The form hasn't been submitted and a pin hasnt been entered so display it
    ?>
        <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
    }
    ?>
    
    PHP:
     
    wd_2k6, Jul 14, 2009 IP