I'm having a go at PHP programming and bumped into some troubles with my syntax. I don't seem to understand PHP well enough to resolve this syntax error, though it should be pretty obvious to a trained eye. I'm hoping I can find the solution to the error here.
I have a login page written in HTML/PHP called login.php:
<?php
session_start();
?>
<html>
<body>
<?php
if (isset($_SESSION["user"])) {
echo "<p>Welcome back, " . $_SESSION["user"] . "!<br>";
echo '<a href="process.php?action=logout">Logout</a></p>';
}
else {
?>
<form action="process.php?action=login" method="post">
<p>The username is: admin</p>
<input type="text" name="user" size="20">
<p>The password is: test</p>
<input type="password" name="pass" size="20">
<input type="submit" value="Login">
</form>
<?php
}
?>
</body>
</html>
which routes to a process.php, where the error happens at line 8 at the ;
<?php
session_start();
switch($_GET["action"]) {
case "login":
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user = (isset($_POST["user"]) &&
ctype_alnum($_POST["user"]) ? $_POST["user"] : null;
$pass = (isset($_POST["pass"])) ? $_POST["pass"] : null;
$salt = '$2a$07$my.s3cr3t.SalTY.str1nG$';
if (isset($user, $pass) && (crypt($user . $pass, $salt) ==
crypt("admintest", $salt))) {
$_SESSION["user"] = $_POST["user"];
}
}
break;
case "logout":
$_SESSION = array();
session_destroy();
break;
}
header("Location: login.php");
?>
The error message I receive from the webserver is the following, and happens whenever I press the "login" button.
Parse error: syntax error, unexpected ';' in /Applications/XAMPP/xamppfiles/htdocs/xsrf/process.php on line 8
Any help with resolving this syntax error would be greatly appreciated.
Cheers!