打开新的php页面
我正在创建一个有登录页面的网站。用户必须输入其用户和密码,如果信息正确,网站应打开/显示包含一些信息的新网站。现在我被困在网站将显示另一个页面的部分,下面是我正在使用的表单(login.php)打开新的php页面,php,html,input,Php,Html,Input,我正在创建一个有登录页面的网站。用户必须输入其用户和密码,如果信息正确,网站应打开/显示包含一些信息的新网站。现在我被困在网站将显示另一个页面的部分,下面是我正在使用的表单(login.php) 从操作中删除home.php位,并使用location将脚本部分替换为php头调用,这将是 header('Location: http://example.com/reports_home.php'); 删除操作以保持在同一页面上: <?php if ( isset($_POST) &a
从操作中删除home.php位,并使用location将脚本部分替换为php头调用,这将是
header('Location: http://example.com/reports_home.php');
删除操作以保持在同一页面上:
<?php
if ( isset($_POST) && !empty($_POST) ) {
$user = $_POST["user"];
$password = $_POST["password"];
if ( $user == "user" && $password == "password" ){ //dummy user & psswd
header("Location: http://example.com/reports_home.php");
}
else{
$message = ERROR;
}
}
?>
<form method="POST" action="" autocomplete="off">
<input name="user" id="fields" type="text" placeholder="user" required><br/>
<input name="password" id="fields" type="password" placeholder="password" required></br>
<input type="submit" id="button" value="OK"></center>
</form>
</div>
<?php if ( isset($message) ): ?>
<center> <p style='color:red';><?php echo $message; ?></center>
<?php endif; ?>
编辑:我在本地试用过,效果不错。打开前检查空间
<?php
在这里,尝试一下,看看我关于密码存储的脚注
旁注:action=“home.php”
已更改为action=”“
,因为它是在同一个文件中执行的
您可以使用and在成功时重定向
否则,您将收到类似的警告:
警告:无法修改标题信息-标题已由(输出从/file.php开始)在
代码:
<?php
ob_start();
?>
<div>
<form method="POST" action="" autocomplete="off">
<input name="user" id="fields" type="text" placeholder="user" required><br/>
<input name="password" id="fields" type="password" placeholder="password" required></br>
<input id="button" name="submit" type="submit" value="OK"></center>
</form>
</div>
<?php
if(isset($_POST['submit'])){
$user=$_POST["user"];
$password=$_POST["password"];
if($user=="user" && $password=="password"){ //dummy user & psswd
// change this to your URL
header("Location: http://www.example.com/success.php");
}
else{
echo "<center> <p style='color:red';>".ERROR."</center>";
}
}
?>
脚注
密码存储
我注意到您可能正在以纯文本形式存储密码。不建议这样做
使用以下选项之一:
- PHP5.5的函数
- 兼容性包(如果PHP<5.5)
其他链接:
标题('Location:'。$newURL)代码>退房。我试过了,但没有。我还尝试了die()
和exit()
,但它只清除实际站点中的所有内容。只是一个警告,这不是一种非常安全的密码处理方式。仍然不起作用TT.TT它只是清除字段并停留在同一页面我在发布之前测试过这个。复制它,完全如图所示。如果你再加上什么,那就是了。在我知道它有效之前,我从不发布任何东西@罗西
<?php
ob_start();
?>
<div>
<form method="POST" action="" autocomplete="off">
<input name="user" id="fields" type="text" placeholder="user" required><br/>
<input name="password" id="fields" type="password" placeholder="password" required></br>
<input id="button" name="submit" type="submit" value="OK"></center>
</form>
</div>
<?php
if(isset($_POST['submit'])){
$user=$_POST["user"];
$password=$_POST["password"];
if($user=="user" && $password=="password"){ //dummy user & psswd
// change this to your URL
header("Location: http://www.example.com/success.php");
}
else{
echo "<center> <p style='color:red';>".ERROR."</center>";
}
}
?>
<?php
if(isset($_POST['submit'])){
$user=$_POST["user"];
$password=$_POST["password"];
if($user=="user" && $password=="password"){ //dummy user & psswd
header("Location: http://www.example.com/success.php");
}
else{
echo "<center> <p style='color:red';>".ERROR."</center>";
}
}
?>
<div>
<form method="POST" action="" autocomplete="off">
<input name="user" id="fields" type="text" placeholder="user" required><br/>
<input name="password" id="fields" type="password" placeholder="password" required></br>
<input id="button" name="submit" type="submit" value="OK"></center>
</form>
</div>