2012-03-29 20 views
2

烦人的是我的登录检查脚本没有重定向到我告诉它的地方。 我知道它正确地打if语句,因为我把回声检查它。 这是公然跳到标题,因为在第一种情况下,它回声“ - 空白”,因为它应该也是“它甚至得到这么远?”标题位置不工作 - 但肯定是通过

所以在这个基础上,我知道它打到头 - 它只是简单地忽略它,我不能为我的生活摸索为什么。

林肯定它的简单,我错过了一些荒谬明显的东西,但我只是不能看到它。 有什么建议吗?

// makes sure they filled it in 
if($_POST['frmLogin-username'] == "" || $_POST['frmLogin-password'] == ""){ 
    echo " - blanks"; 

    header('Location: ?page=landing&action=login&message=1'); 
    echo "Did it even get this far?"; 
    die; 
} 
else{ 
    // checks it against the database 
    $query = mysql_query("SELECT * FROM shops WHERE shopUsername = '".$_POST['frmLogin-username']."'"); 

    //Gives error if user dosen't exist 
    $count = mysql_num_rows($query); 

    if ($count == "0"){ 
     echo " - no user"; 
     header('Location: ?page=landing&action=login&message=2'); 
     die; 
    } 
    else{ 

     while($row = mysql_fetch_array($query)){ 

      //gives error if the password is wrong 

      if ($_POST['frmLogin-password'] != $row['shopPassword']){ 
       echo " - wrong pass"; 
       header('Location: ?page=landing&action=login&message=3'); 
       die; 
      } 

      else{ 

       // if login is ok then we add a cookie 

       $hour = time() + 3600; 

       setcookie(shopusername, $_POST['frmLogin-username'], $hour); 
       setcookie(shopid, $row['shopId'], $hour); 

       //then redirect them to the shop panel 
       header("Location: ?page=shop"); 
       die; 
      } 
     } 
    } 
} 

编辑:这个问题是我有通过调用加载的index.php内我的所有网页的方式做包括我现在正在研究 我纷纷出招这个过程页面到它自己的PHP文件,它现在的作品很好

+1

你可以发送文本内容到浏览器后不发送标题 - 任何回声或空白都将阻止页面重定向。 – 2012-03-29 20:08:59

+1

此外,根据HTTP规范,您必须提供完整的URI到位置,而不是相对路径。 (虽然这可能不是问题,因为任何现代浏览器都可以容忍这个问题。) – Corbin 2012-03-29 20:10:12

+0

回声通常不存在 - 它们被添加用于测试 – TomK89 2012-03-29 20:13:26

回答

2

的问题是与我通过调用加载的index.php内我的所有网页的方式做包括我现在正在研究我提出这个过程页面到它自己的PHP文件,现在正常工作

2

首先:在输入任何内容后,如Sam在他的评论中所说的,使用echo时不能发送标题。

其次,要发送重定向,Location:之后的URL必须是绝对的,例如http://localhost/page/to/redirect/to.php

编辑
科尔宾居然打我我的回答大约10秒钟;-)

+0

我已经使用了一个绝对URL并且通常不会有回声(他们被添加到检查我的代码正确击中IF语句,只是没有删除在这里发布前) 即使绝对它仍然无法正常工作 – TomK89 2012-03-29 20:19:23

1

您可以在PHP中使用window.location,只是echo它。