douyousu9691 2012-10-12 17:07
浏览 15
已采纳

php标题根本没有重定向

Ok so I asked this question before and got a lot of good answers unfortunately none of them changed the outcome. I'm trying to redirect after a 'login' page on the site I'm working on. I'm gathering the id in a session and trying to redirect. This works fine in a lot of the sites I use, the one difference with this site is that it doesn't use localhost, it has a server name. At first I had an echpo before the header and everyone told me that was the problem, I removed it to fix it but nothing changed. Here's the code:

<?php 
/*set all the variables*/ 
$email = $_POST['email']; 

$password = sha1($_POST['password']);   /* hash the password*/ 

$conn = mysqli_connect ('servername', 'username', 'password', 'databasename') or die('Error connecting to MySQL server'); 
/*select the id from the users table that match the conditions*/ 
$sql = "SELECT id FROM users WHERE email = '$email' AND password = '$password'"; 

$result = mysqli_query($conn, $sql) or die('Error querying database.'); 

$count = mysqli_num_rows($result); 

if ($count == 1) { 

$row = mysqli_fetch_array($result); 

session_start(); 

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

/*If true head over to the users table*/ 
header('location: users_table.php'); 


} 
/*If invalid prompt them to adjust the previous entry*/ 
else { 
echo '<h2>Invalid Login</h2><br />'; 
echo '<h2>Click <a href="javascript:history.go(-1)">HERE</a> to go back and adjust your entry.</h2>'; 
                    } 


mysqli_close($conn); 

?> 

The only other code on the page are the HTML HEAD and BODY tags. I've even asked one of my old college teachers for help and he said the code looks fine, he can't find the problem. so I'm asking again. Is there maybe a way I can use an HTML or SCRIPT redirect and stay in the session?

Thanks

  • 写回答

4条回答 默认 最新

  • dongshi4773 2012-10-12 17:15
    关注

    check for these problems

    do you have header already sent? if yes then this is what making it not run. check for php errors or blank lines before

    exit;
    

    after header function like

    header('Location: users_table.php'); 
    exit;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?