[請益] 關於登入問題

看板PHP作者 (好猶豫喔)時間17年前 (2008/05/14 18:35), 編輯推噓3(304)
留言7則, 5人參與, 最新討論串1/2 (看更多)
我找了好久... 還是不知道問題在哪? 感覺警告可以不必太在意 可是要的畫面跑不出 來 所以就在懷疑是不是警告的東西很重要… 問題:輸入正確帳號密碼 沒辦法切換到登入成功的頁面 (從login.php想進到hw1-2.php畫面) (以下是警告訊息) Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\login.php:6) in C:\AppServ\www\login.php on line 29 問題:一進去畫面就看到警告(感覺和上面的警告很像是 Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\login.php:6) in C:\AppServ\www\login.php on line 37 ----------------------------------------程式碼-------------------------------- 下面是login.php的程式碼 <html> <head><title>登入網站</title></head> <body> <center> <h2>輸入使用者名稱和密碼登入網站</h2> <hr><small><font color="red"> <?php // session_start(); // 啟動Session $username = ""; $password = ""; $username1 = "test1"; $password1 = "pwd1"; $username2 = "test2"; $password2 = "pwd2"; // 取得表單欄位的使用者名稱和密碼 if (isset($_POST["Username"])) $username = $_POST["Username"]; if (isset($_POST["Password"])) $password = $_POST["Password"]; // 檢查使用者名稱和密碼  if ( ($username == $username1) && ($password == $password1) ) { header("Location:hw1-2.php"); //第二十九行 }else{ if ( ($username == $username2) && ($password == $password2) ) { header("Location:hw1-2.php"); }else{ header("location:hw1-3.php"); //第三十七行 } } ?> </font></small></center> <form action="login.php" method="post"> <table align="center" bgcolor="#FFCC99"> <tr><td>使用者名稱 : </td> <td><input type="text" name="Username" size="15" maxlength="10"></td></tr> <tr><td>使用者密碼 : </td> <td><input type="password" name="Password" size="15" maxlength="10"></td></tr> <tr><td colspan="2" align="center"> <input type="submit" value="登入"> <input name="reset" type="reset" value="清除" /></td></tr> <tr><td colspan="2" align="center">&nbsp;</td> </tr> </table> </form> </body> </html> --------------------------------------程式碼--------------------------------- 下面是hw1-2.php程式碼: <html> <head> <title>登入成功</title> <meta http-equiv="Content-Type" content="text/html; charset=big5"><style type="text/css"> <!-- body,td,th { color: #666666; } body { background-color: #FFCCFF; } --> </style></head> <h2>登入成功畫面</h2> <body> <table width="348" border="1"> <tr> <th width="156" scope="col">帳號</th> <th width="176" scope="col">登入日期</th> </tr> <tr> <td><?php echo $username?> </td> <td><?php echo date('Y-m-d')?> </td> </tr> </table> </body> </html> ----------------------------------------------------------------------- 謝謝 -- http://class.ruten.com.tw/user/index00.php?s=emily4531189 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.81.226.8

05/14 18:58, , 1F
爬文:p session有關要在最前面 還有存檔存無BOM
05/14 18:58, 1F

05/14 19:03, , 2F
不懂什麼是存無bon??謝謝
05/14 19:03, 2F

05/14 20:30, , 3F
^M <- bon
05/14 20:30, 3F

05/14 20:50, , 4F
設定output_buffer 4096 就可以了 懶得處理的話
05/14 20:50, 4F

05/15 02:22, , 5F
謝謝大家
05/15 02:22, 5F

05/15 10:26, , 6F
把判斷使用者跟密碼的程式碼放在最前面就可以了
05/15 10:26, 6F

05/15 23:45, , 7F
^^
05/15 23:45, 7F
文章代碼(AID): #18Ai2A41 (PHP)
文章代碼(AID): #18Ai2A41 (PHP)