[請益] 使用者登入語法問題

看板PHP作者 (孤獨的月兔)時間16年前 (2009/02/27 00:34), 編輯推噓3(302)
留言5則, 3人參與, 最新討論串1/1
這是我目前做使用者登入的語法 程式碼是dremaweaver自己跑的 if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "index.html"; $MM_redirectLoginFailed = "login_form.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_connection, $connection); $LoginRS__query=sprintf("SELECT username, password FROM member WHERE username=%s AND password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $connection) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } 所有的頁面相關設定都用好後 輸入賬號密碼按登入 卻總是無法進入下個頁面(index.html) 然後出現 Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\test2.php:2) in C:\AppServ\www\test2.php on line 75 看來問題是出在上述兩段 header("Location: " . $MM_redirectLoginSuccess ); header("Location: ". $MM_redirectLoginFailed ); 但是我卻不知道到底錯在哪... 希望有高手幫我指名一下 附註: COOKIE開了 再php.ini中output_buffering也改成On或4096 甚至也把檔案存成UTF-8 無BOM 但是依然跑出這樣的錯誤 是程式問題還是我的電腦問題= =a 修改 ----------------------------------------------- 之後我用 echo("<script language='javascript'>location.href='".$MM_redirectLoginSuccess."'</script>"); 直接去代替原本的 header("Location: " . $MM_redirectLoginSuccess ); (下一行也同樣方法) 結果就可以了....(抱歉我太新了 這問題搞了我2天...) 但是還是不知道原因 是DW內建的HEADER語法有錯誤嗎?還是我使用方法錯誤? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.44.73.86

02/27 00:44, , 1F
先把 or die(mysql_error()); 拿掉試試看
02/27 00:44, 1F

02/27 00:46, , 2F
and 找找header前有沒有多餘的空白或是輸出之類的
02/27 00:46, 2F

02/27 03:07, , 3F
試過了,不行呢
02/27 03:07, 3F
※ 編輯: pili11111 來自: 114.44.73.86 (02/27 03:12)

02/27 07:02, , 4F
utf-8 是不是沒有把BOM去掉??
02/27 07:02, 4F

02/27 07:02, , 5F
眼殘 抱歉^^
02/27 07:02, 5F
文章代碼(AID): #19fiII0c (PHP)
文章代碼(AID): #19fiII0c (PHP)