2012-08-05 33 views
0
if(isset($_SESSION['username']) && isset($_SESSION['password'])){ 
header("Location: ../welcome/index.php"); 

我的登錄腳本似乎已經停止工作,最近7月19日PHP的新更新。header(「location:...」);沒有重定向到新的PHP更新

任何人都可以解決這個問題嗎?

這是整個腳本。


<? 
    include_once ('includes.inc.php'); 


    if (!isset($_POST['login']) || (strlen($_POST['username']) < 3) || (strlen($_POST['password']) < 3)) { //User forgot a field 
     header("Location: ../index.php?message=4"); 
    } 
    else { 
     $username = htmlspecialchars(mysql_real_escape_string(trim($_POST['username'])), ENT_QUOTES); 
     $password = sha1(trim($_POST['password'])); 
     $sqlPass = mysql_query("SELECT isbanned, password, id FROM members WHERE username = '" . $username . "'"); 
     $sqlPass = mysql_fetch_array($sqlPass); 


     if (($sqlPass['password'] == NULL) || ($sqlPass['password'] != $password)) { //User entered wrong information 
      header("Location: ../index.php?message=5"); 
     } 
     else if ($sqlPass['isbanned'] == '1') { 
      header("Location: ../index.php?message=50"); 
     } 
     else { 
      $_SESSION['username'] = $username; 
      $_SESSION['password'] = $password; 
      $_SESSION['uid']  = $sqlPass['id']; 

      //Log IP 
      AddIPToLogs(); 


      if (isset($_SESSION['username']) && isset($_SESSION['password'])) { 
       header("Location: ../welcome/index.php"); 
      } 
     } 
    } 
?> 
+0

歡迎來到Stack Overflow!請正確格式化您的代碼。通過在任何代碼行之前縮進4個空格來插入代碼塊。我這次爲您編寫了代碼格式,但下次請正確格式化。如需進一步的幫助,請參閱[編輯常見問題](http://stackoverflow.com/editing-help#code) – 2012-08-05 19:24:28

+0

酷,盡我所能。但是,無論如何,我可以得到這個幫助嗎? – user1577774 2012-08-05 19:25:49

+0

另外,歡迎使用堆棧溢出!請不要使用'mysql_ *'函數來編寫新的代碼。他們不再維護,社區已經開始[棄用程序](http://goo.gl/KJveJ)。請參閱* [紅盒子](http://goo.gl/GPmFd)*?相反,您應該瞭解[準備好的語句](http://goo.gl/vn8zQ)並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli的)。如果你不能決定哪些,[這篇文章](http://goo.gl/3gqF9)會幫助你。如果你選擇PDO,[這裏是很好的教程](http://goo.gl/vFWnC)。 – 2012-08-05 19:26:29

回答

2

嘗試<?php作爲起始標記,而不是<?

或者你用在session_start()?

或者您是否曾經在任何地方發過標頭?

是否有任何錯誤,PHP顯示?

+0

'<?php'應該可以解決你的問題! – rackemup420 2012-08-05 19:31:28

+0

我是這麼認爲的,但是沒有太多的問題。 – androbin 2012-08-05 19:34:14

+0

抱歉,這裏是你的鏈接。 http://php.net/manual/en/ini.core.php – rackemup420 2012-08-05 19:37:09

0

我首先想到的是,查看提供的代碼,是您的if語句有語法錯誤。聲明:

if (!isset($_POST['login']) || (strlen($_POST['username']) < 3) || (strlen($_POST['password']) < 3)) { //User forgot a field 
    header("Location: ../index.php?message=4"); 
} 

應該

if ((!isset($_POST['login']) || (strlen($_POST['username']) < 3) || (strlen($_POST['password']) < 3)) { //User forgot a field 
    header("Location: ../index.php?message=4"); 
} 

此外,您在 '頭(' 位置 ')' 之前,有一個 '包括' 語句。您所包含的代碼中可能存在問題。

最後,您應該詳細說明如何更新系統,從哪個版本的PHP到最新的版本。你是自己做這個更新的,還是你在一個網站託管的服務器上運行?

+0

我正在使用iPage進行託管。 – user1577774 2012-08-05 19:59:25