duanchoupo1104 2014-03-18 14:19
浏览 60

为什么我的页面忽略了标题('Location:home /'); 码?

I have a login script that checks user credentials against a database, and if they are correct will assign them a session then forward them to the home screen.

For some reason, it will not forward, but will happily output text that appears after it should have read the forwarding code.

<?php
//require_once('scripts/include.php');
require_once('scripts/includePDO.php');

$error = '';
$form = $_POST['submit'];
$email = $_POST['email'];
$password = $_POST['password'];

if( isset($form) ) {
if( isset($email) && isset($password) && $email !== '' && $password !== '' ) {

$sql = "SELECT * FROM tbl_users WHERE email = :email and password = :password";

$q   = $conn->prepare($sql);
        $q->bindValue(':email',$email,PDO::PARAM_STR);
        $q->bindValue(':password',$password,PDO::PARAM_STR);
        $q->execute();

            $r = $q->fetch(PDO::FETCH_ASSOC);
            if(($r)!=0)

{ //success

$answer = $r['id'];

$_SESSION['logged-in'] = true;
$_SESSION['who'] = $answer;

echo "This text echos no probelm";

//If the login details are entered and they match those in the database, forward to new page.
header('Location: home/');

echo "Even this text will be shown";

exit;

// If information is wrong or missing, provide error message.
} else { echo "Sorry, something hasn't worked. Are you entering all the information correctly?"; }
} 

}

?>
  • 写回答

4条回答 默认 最新

  • 啊啊啊小孔 2014-03-18 14:21
    关注

    There should be no output sent to the browser before the header statement. You will get headers already sent error(if enabled)

    echo "This text echos no probelm";
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度