我正在尝试使用angularjs和PHP进行登录。但遇到问题我无法理解为什么?
<?php
date_default_timezone_set("Asia/Bangkok");
session_start();
$data = json_decode(file_get_contents("php://input"));
$email = mysql_real_escape_string($data->email);
$password = mysql_real_escape_string($data->password);
{
$con=mysqli_connect("localhost","root","thanh03021986","erp");
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = mysqli_query($con,"SELECT email, password FROM user WHERE email = '$email'");
$numrow = mysqli_num_rows($query);
if($numrow > 0){
while($rows = mysqli_fetch_array($query))
{
$dbemail = $rows['email'];
$dbpassword = $rows['password'];
}
$con->close();
if($email==$dbemail && $password == $dbpassword){
$_SESSION['uid'] = $email;
header('location:/A.php');
}
}
}
?>
当If()
返回true
$_SESSION['uid'] = $email
有效但header('location:/A.php');
不起作用时。我尝试将header('location:/A.php');
放出IF()
,标题有效吗???请帮忙解释一下?
答案 0 :(得分:1)
必须首先调用session_start
函数,并且必须在任何HTML代码之前调用header
函数。
请参阅header
函数manual
答案 1 :(得分:1)
使用header
进行重定向,您必须确保html中没有任何内容(甚至不是<html>
标记)和绝对路径。所以,你应该这样做才能工作:
header('Location: http://pathblablabla.bla/A.php');
另外,请注意我放置位置,而不是位置。不确定它是否区分大小写,但以防万一...