New to php programming, simple syntax error which I can't seem to resolve -
this question has answer here:
- php parse/syntax errors; , how solve them? 11 answers
i'm having go @ php programming , bumped troubles syntax. don't seem understand php enough resolve syntax error, though should pretty obvious trained eye. i'm hoping can find solution error here.
i have 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 process.php, error happens @ line 8 @ ;
<?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 receive webserver following, , happens whenever press "login" button.
parse error: syntax error, unexpected ';' in /applications/xampp/xamppfiles/htdocs/xsrf/process.php on line 8
any resolving syntax error appreciated.
cheers!
you forgot close parenthesis.
try change :
$user = (isset($_post["user"]) && ctype_alnum($_post["user"]) ? $_post["user"] : null;
by :
$user = (isset($_post["user"]) && ctype_alnum($_post["user"])) ? $_post["user"] : null;
Comments
Post a Comment