我是一个nood在phpand html也javascript,我特灵使一个登录系统与html和php和javascript如果有必要,但这里有一个问题,这是我不知道如何导航到其他页面登录后(我尝试使用header()之前,但失败了,因为它必须是,但在代码的froung后,而不是.
这是启动登录代码
<?php
session_start();
?>
<!DOCTYPE HTML>
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
Password: <input type="text" name="password"><br>
<input type="submit">
</form>
</body>
</html>
它叫做index.php
这是一个名为welcome.php的登录过程页面
<?php
session_start();
?>
<html>
<body>
<p id="demo">hello</p>
<?php
$namee=fopen("name.txt", "r") or die("Unable to open file!");
$passworde=fopen("password.txt", "r") or die("Unable to open file!");
$name=fgets($namee);
$password=fgets($passworde);
$savename = fopen("savename.txt", "w");
$savepassword = fopen("savepassword.txt", "w");
$nameinput = $_POST["name"];
$passwordinput = $_POST["password"];
if ($name == htmlspecialchars($_POST["name"]) AND $password == htmlspecialchars($_POST["password"])) {
echo $_POST["name"];
echo $_POST["password"];
fwrite($savename, $_POST["name"]);
fwrite($savepassword, $_POST["password"]);
} else {
echo "permission denied";
}
?>
<p id="dem">awef</p>
<script>
window.alert(5 + 6);
document.getElementById("demo").innerHTML = "wtf";
var nameinput=<?php $_POST["name"]?>;
var passwordinput=<?php $_POST["password"]; ?>;
var name=<?php $name; ?>;
var password=<?php $password; ?>;
var closesavename=<?php fclose($savename); ?>;
var closesavepassword=<?php fclose($savepassword); ?>;
function jump{
location.replace("https://MobileWigglyImplementation.gepingyi.repl.co/mainpage.php")
}
if (nameinput == name AND passwordinput == password) {
closesavename
closesavepassword
jump()
exit()
</script>
</body>
</html>
这是我想导航到的页面,命名为mainpage.php
<?php
// We need to use sessions, so you should always start sessions using the below code.
session_start();
// If the user is not logged in redirect to the login page...
$openname = fopen("savename.txt", "r");
$openpassword = fopen("savepassword.txt", "r");
$readname = fgets($openname);
$readpassword = fgets($openpassword);
$namee=fopen("name.txt", "r") or die("Unable to open file!");
$passworde=fopen("password.txt", "r") or die("Unable to open file!");
$name=fgets($namee);
$password=fgets($passworde);
if ($readname == $name AND $readpassword == $password) {
echo "good";
fclose($openname);
fclose($openpassword);
fclose($namee);
fclose($passworde);
} else {
fclose($openname);
fclose($openpassword);
fclose($namee);
fclose($passworde);
echo "erro";
}
echo "good bro";
?>
<!DOCTYPE html>
<html>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body>
</html>
此名称. txt
james
这是密码. txt
123456
当我输入james作为用户名,输入123456作为密码时,输出如下
hello
james123456
awef
我期待它跳转到mainpage.php
1条答案
按热度按时间jogvjijk1#
您可以使用报头进行重定向。请参阅以下内容: