gpt4 book ai didi

php - 添加 SSL 证书后登录表单不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 15:01:50 24 4
gpt4 key购买 nike

我有一个登录表单:

<form method="post" action="verify.php" name="loginform">
<table border="0" bgcolor="orange" align="center">
<tr><td colspan="3"><h1><b>Please Enter Username and Password</b></h1></td></tr>
<tr>
<td><label>User Name</label>
</td>
<td>:
</td>
<td><input type="text" name="user"/>
</td>
</tr>
<tr><br/>
<td><label>Password</label>
</td>
<td>:
</td>
<td><input type="password" name="pwd"/>
</td>
</tr>
<tr><td colspan="3" align="center"><input type="submit" class="submit-green" value="Login"/></td>
</tr>
</table></form>

我有 verify.php 作为

<?php
session_start();
include "dbconfig.php";
$user=$_POST['user'];
$pwd=sha1($_POST['pwd']);

$sql='select * from admin where username="'.$user.'" AND password="'.$pwd.'"';
$res=mysql_query($sql) or die('Login query error:'. mysql_error());
if(mysql_num_rows($res)==1)
{
header("Location:index");
}
else
{
header("Location:login.php");
}
$row = mysql_fetch_array($res);
$_SESSION['admin']=$row['id'];
?>

这里有错误吗?我找不到任何错误。在我的网站上使用 SSL 证书之前,它工作正常。现在它不起作用。我做了一个 print_r 请求以了解通过 post 方法获得的值。但只有密码正在获取,而且它是一个错误的 SHA1 值。为什么会这样?

最佳答案

从 HTTP 切换到 HTTPS 时,您将丢失 session ,因为 HTTPS session cookie 上设置了 Secure 标志,因此只能通过 HTTPS 访问它们。这意味着当您切换到 HTTPS 时,您无法传输旧的 HTTP session cookie。您可以尝试将 HTTP session 传递给 HTTPS。

这是取自 another answer 的示例:

HTTP代码:

$currentSessionID = session_id();
header('https://yoursite.com/login.php?session='.$currentSessionID);

HTTPS 代码:

// Retrieve the session ID as passed via the GET method.
$currentSessionID = $_GET['session'];

// Set a cookie for the session ID.
session_id($currentSessionID);

显然,您会想让它更安全。这只是一个传达一般思想的简单示例。

关于php - 添加 SSL 证书后登录表单不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20787110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com