-2

I was attempting to write a password-protect page in php

<?php
$pass = $_POST['pass'];

if(password_verify($user, '$argon2i$v=19$m=2048,t=4,p=3$Y3NGc25QQ1k1cTBkTHZNRg$skaHiTZAiAYB2bwme/KBhRujlJNXWd7jkji4vP5t5zM')) //hash is Admin
{
  header("Location: secure.html");
  exit();
}
else
{
    if(isset($_POST))
    {?>

            <form method="POST" action="index.php">
            Pass <input type="password" name="pass"></input><br/>
            <input type="submit" name="submit" value="Go"></input>
            </form>
    <?}
}
?>

However, I keep getting the error:

PHP Parse error:  Unclosed '{' on line 15 in /home/cody/Desktop/code/Web/secureSignIn/index.php on line 25

This error was not present when working with PHP on Replit. Can anyone explain why this error is showing?

I tried replacing <? with <?php, adding <? php error_reporting(0); ?>, and using echo to run the HTML (Which only printed it to console and did not execute.

Cody
  • 3
  • 2
  • `` should be ` – Barmar Feb 16 '23 at 21:54
  • A typo? The first PHP code block is opened with ` – David Feb 16 '23 at 21:54
  • I tried that and the error did not change – Cody Feb 16 '23 at 21:54
  • You also need a space between ` – Barmar Feb 16 '23 at 21:56
  • "replacing with – Cody Feb 16 '23 at 21:57
  • Ok thank you Bamar, but now I have an error when visiting the website: 127.0.0.1:49270 [404]: GET / - No such file or directory – Cody Feb 16 '23 at 21:59
  • Here is the request header: GET / HTTP/1.1 Host: localhost:8000 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate, br Connection: keep-alive Upgrade-Insecure-Requests: 1 Sec-Fetch-Dest: document Sec-Fetch-Mode: navigate Sec-Fetch-Site: none Sec-Fetch-User: ?1 – Cody Feb 16 '23 at 22:05

1 Answers1

-1

This should work:

  • put the <?php starttag in a seperate line
  • start again with <?php and not only <?

<?php
$pass = $_POST['pass'];
if(password_verify($user, '$argon2i$v=19$m=2048,t=4,p=3$Y3NGc25QQ1k1cTBkTHZNRg$skaHiTZAiAYB2bwme/KBhRujlJNXWd7jkji4vP5t5zM')) //hash is Admin
{
    header("Location: secure.html");
    exit();
}  
else
{
    if(isset($_POST))
    {?>
        <form method="POST" action="index.php">
        Pass <input type="password" name="pass"></input><br/>
        <input type="submit" name="submit" value="Go"></input>
        </form>
    <?php
    }
}
?>
jpxr
  • 16
  • 2