PHP gives error that is not present when using replit

64 Views Asked by At

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.

1

There are 1 best solutions below

0
jpxr On BEST ANSWER

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
    }
}
?>