Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我有一个登录页面,配置文件页面不工作_Php_Mysql_Session - Fatal编程技术网

Php 我有一个登录页面,配置文件页面不工作

Php 我有一个登录页面,配置文件页面不工作,php,mysql,session,Php,Mysql,Session,我有一个登录页面,允许用户输入电子邮件和密码,然后提交,系统检查数据是否正确,它会显示配置文件页面,如果不正确,它会显示一条消息,通知用户数据不正确 但问题是,如果我把标题(“Location:profile.php”)系统不工作 但如果我回显一条消息,通知用户数据正确,浏览器将毫无问题地显示此消息 login.php 在php关闭标记之前使用ob\u end\u flush()?>您可以在配置文件页面上使用javascript重定向。因为如果任何小错误,比如打印前或任何空格php header

我有一个登录页面,允许用户输入电子邮件和密码,然后提交,系统检查数据是否正确,它会显示配置文件页面,如果不正确,它会显示一条消息,通知用户数据不正确

但问题是,如果我把标题(“Location:profile.php”)系统不工作 但如果我回显一条消息,通知用户数据正确,浏览器将毫无问题地显示此消息

login.php
在php关闭标记之前使用
ob\u end\u flush()
?>

您可以在配置文件页面上使用javascript重定向。因为如果任何小错误,比如打印前或任何空格php header()函数都可能导致一些问题。。因此,更好的用户javascript

用下面的代码检查

?>
<script>
window.location.href="profile.php";
</script>
<?
?>
window.location.href=“profile.php”;

我对profile.php的这一行有疑问

require_once('include/connect.php')

如果profile.php的路径有错误,则必须更改

标题(位置:“xyz/profile.php”)

请检查此相对路径是否正确

试试这个

<?php
session_start();
ob_start();
error_reporting(E_ALL);
require_once('include/connect.php');
//$message = ""; 
if(isset($_POST['email']))
{

 $email = $_POST['email'];
 $pass = $_POST['pass'];

 $email1 = mysql_real_escape_string(strip_tags($email));
 $pass1 = mysql_real_escape_string(strip_tags($pass));
 //$pass = md5($pass);

 $sql = mysql_query("SELECT user_id, email_address, first_name FROM user WHERE email_address='$email1' AND password='$pass1' LIMIT 1") or die("error in user table");
 $login_check = mysql_fetch_assoc($sql)

if($login_check)
{
   $row = $login_check;

      $id = $row['user_id'];
      $_SESSION['user_id'] = $id;

      $firstname = $row['first_name'];
      $_SESSION['first_name']= $firstname;

      $email = $row['email_address'];
      $_SESSION['email_address']= $email;

      mysql_query("UPDATE user SET last_log_date=now() WHERE user_id='$id'");

    //$message = "correct email and passworddd!!";  
      header("Location: profile.php");
      exit();     
}//close if 
else
{
  //$message = "incorrect Email or Password!!";
  //exit();
}
}//close if

?>  

您的登录检查是否正确?意思是你得到了关于注册用户的正确信息?“不起作用”-你需要比这更具体。如果我们知道它到底是如何“不起作用”的,这会有帮助。错误消息是什么?您可以查看位于基于debian的系统中/var/log/apache2/的错误日志吗?@user2207792是正确的,只是重定向问题标题(“location:profile.php”);这就是问题所在,从昨天到现在,我一直试图修复此错误,但没有成功。我确实使用了ob_end_flush(),但仍然存在相同的问题。请尝试删除
exit()
i删除exit(),但仍然存在相同的问题。您确定,
select
语句会产生一行吗?也许
$login\u check
是0@amir no我对$id$firstname和电子邮件做了一个var\u转储,它返回了正确的数据只需注释你的header函数并复制此代码并粘贴到那里。。然后运行你的代码。我认为更好的实际方法是输出缓冲。。。。不是js。。。如果js不可禁用,你是对的,但这是一个快速的方法,因为如果我们在php头中有错误,那么很难找到,而且需要花费大量时间来检查。@user2360853请在冒号状头后留出空间(“Location:profile.php”)@user2360853查看我的更新答案并重试。如果有任何问题,请告诉我。
?>
<script>
window.location.href="profile.php";
</script>
<?
<?php
session_start();
ob_start();
error_reporting(E_ALL);
require_once('include/connect.php');
//$message = ""; 
if(isset($_POST['email']))
{

 $email = $_POST['email'];
 $pass = $_POST['pass'];

 $email1 = mysql_real_escape_string(strip_tags($email));
 $pass1 = mysql_real_escape_string(strip_tags($pass));
 //$pass = md5($pass);

 $sql = mysql_query("SELECT user_id, email_address, first_name FROM user WHERE email_address='$email1' AND password='$pass1' LIMIT 1") or die("error in user table");
 $login_check = mysql_fetch_assoc($sql)

if($login_check)
{
   $row = $login_check;

      $id = $row['user_id'];
      $_SESSION['user_id'] = $id;

      $firstname = $row['first_name'];
      $_SESSION['first_name']= $firstname;

      $email = $row['email_address'];
      $_SESSION['email_address']= $email;

      mysql_query("UPDATE user SET last_log_date=now() WHERE user_id='$id'");

    //$message = "correct email and passworddd!!";  
      header("Location: profile.php");
      exit();     
}//close if 
else
{
  //$message = "incorrect Email or Password!!";
  //exit();
}
}//close if

?>