我的登录系统在我的Localhost中运行正常,但在Godaddy的服务器中运行不正常。这似乎是header()函数的问题。但我在头文件之前没有回应任何东西
<?php
{
session_start();
include_once 'db_connect.php';
if (isset($_POST))
{
$email = $_POST['email'];
$logpwd = $_POST['password'];
$stmt = $conn->prepare("SELECT password FROM members WHERE email = ? LIMIT 1");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
// get variables from result.
$stmt->bind_result($password);
$stmt->fetch();
// Check if a user has provided the correct password by comparing what they typed with our hash
if (password_verify($logpwd, $password))
{
$sql = "SELECT * from members WHERE email LIKE '{$email}' LIMIT 1";
$result = $conn->query($sql);
$row=mysqli_fetch_array($result);
$_SESSION['user_check'] = 1;
$_SESSION['email'] = $row['email'];
$_SESSION['id'] = $row['id'];
header('Location: ../index.php');
}
else {
header('Location: ../login.php?error=cred');
}
}
}
?>
登录表格如下所示
<form class="form-horizontal" method="post" action="functions/fn_login.php">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email / Mobile No." required name="email">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password" required name="password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
<div class="checkbox">
<label>
<input type="checkbox"> Remember?
</label>
</div>
</div>
<div class="col-sm-6">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</form>
db_connect.php
<?php
$conn = new mysqli('localhost', 'username', 'password', 'usersystem');
?>
我的代码可能存在什么问题。我做错了吗
注意:localhost和Godaddy都有PHP版本5.5
答案 0 :(得分:0)
可能会有一些警告不会在您的localhost服务器上生成,但会在Godaddy的服务器上打印,从而阻止header()
功能。您应该检查服务器的日志文件以查看是否记录了任何错误。
如果您在Chrome中对此进行测试,则应按F12激活调试控制台,然后单击“网络”选项卡,以查看浏览器是否收到重定向。