PHP+mysql登陸問題和sesiion問題

來源:互聯網
上載者:User
首頁面報錯了,錯誤是:Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at F:\Apache HTTP Server\AppServ\www\ClassWeb\ClassWeb.php:8) in F:\Apache HTTP Server\AppServ\www\ClassWeb\ClassWeb.php on line 7
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\Apache HTTP Server\AppServ\www\ClassWeb\ClassWeb.php:8) in F:\Apache HTTP Server\AppServ\www\ClassWeb\ClassWeb.php on line 7


/**********首頁面代碼classweb.php**************/
精品課程網




精品課程網





}
?>



/**************跳轉登陸代碼denglu.php*****************/
session_start();
$username=$_POST['username'];
$password=$_POST['password'];
@ $db = mysql_connect('localhost','root','root'); //串連資料庫
if (!$db) {
die('Could not connect: ' . mysql_error());
}
//echo '串連成功!';
mysql_select_db('wwj'); //選擇資料庫檔案wwj
//執行SQL 陳述式
mysql_query("set names utf8");//資料庫中是utf8 ,沒有“-”.網頁中有!!
$sql="select * from pre_common_member where username=$username";
$result=mysql_query($sql);
if($row=mysql_fetch_assoc($result)){
if($row['password']==md5($password)){
$name=$row['username'];
echo"";
session_register('$name');
header('Location:ClassWeb.php');exit();
}
}
echo"";
header('Location:ClassWeb.php');exit();
mysql_free_result($result);
?>

上面的代碼有點多,我知道大家看起來很煩,但是我真的不知道怎麼搞的了,希望幫忙一下啊,為找不到原因了。謝謝了!!
順便幫我看一下跳轉的登陸頁面代碼 有沒有錯誤,謝謝了,真的謝謝!!


回複討論(解決方案)

把 放在檔案開始處

session_start() 之前不能有任何輸出

session_start(); 之前不能有任何?出。把session_start(): 放在檔案最前可解?此??。

我也試過,放在最前的,可是還是這樣錯誤!!我把 這句話 放第一行 錯誤提示就是第一行了。 求指教啊!!!


session_start();
?>
改成
@session_start();
?>

有BOM頭吧,用編輯器儲存為utf-8 無bom格式。

變更檔編碼,改成utf-8無bom頭

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.