this code is giving back a blank page in browser. Can you spot any mistake? permissions and url checked. The phpcodechecker.com says it's allright
<?php
# Check for POST login data, else set initial values
if (isset($_POST["user"])) {
$user=$_POST['user'];
$pass=hash('sha256',$_POST['pass']);
}
else {
$user="";
$pass="";
}
# Check Login Data
#
# Password is hashed (SHA256). In this case it is 'admin'.
if($user == "admin"
&& $pass == "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918")
{
# Load content from local storage
include("../localstorage/content.html");
}
else
{
# Show login form. Request for username and password
echo
'<html>
<body>
<form method="POST" action="">
Username: <input type="text" name="user"><br/>
Password: <input type="password" name="pass"><br/>
<input type="submit" name="submit" value="Login">
</form>
</body>
</html>'
}
?>
(I downloaded it from http://www.canbike.org/information-technology/2014/02/05/php-simple-password-protection-with-session-timeout.html and i'm concious of its lack of safety)
use echo statement to print the html code as follows.
echo '<html>
<body>
<form method="POST" action="">
Username: <input type="text" name="user"><br/>
Password: <input type="password" name="pass"><br/>
<input type="submit" name="submit" value="Login">
</form>
</body>
</html>';
and remove the in between php tags, use only outer php tags at the beginning and end.
使用了快捷方式开放标签,但不允许从底部向上第三行吗?
<?
I am late for this question but anyway i want to answer this question. First of all, if you are new in PHP then You should change error_reporting line in your php.ini as follows:
error_reporting=E_ALL
because this setting display Parse Error instead of Black Page if there is any parse error.
Solution of your question: There is a Syntax Error in last 'echo' statement of your script which is generating Parse Error . You can remove this syntax error by adding semicolon(;) in last echo statement as follow:
else{
echo
'<html>
<body>
<form method="POST" action="">
Username: <input type="text" name="user"><br/>
Password: <input type="password" name="pass"><br/>
<input type="submit" name="submit" value="Login">
</form>
</body>
</html>';
}
?>
You can use docstring to write html in php files.
<<<EOD
<html>
<body>
<form method="POST" action="">
Username: <input type="text" name="user"><br/>
Password: <input type="password" name="pass"><br/>
<input type="submit" name="submit" value="Login">
</form>
</body>
</html>
EOD;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.