[請益] 是ob使用方式錯誤還是我的寫法不對?

看板PHP作者 (阿飛)時間16年前 (2009/10/06 00:53), 編輯推噓5(501)
留言6則, 5人參與, 最新討論串1/1
請問一下各位大大 以下是我用dw做的,由於測試的時候會顯示 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\AppServ\www\login.php:1) in C:\AppServ\www\login.php on line 92884792 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\login.php:1) in C:\AppServ\www\login.php on line 1450498949 我就在session_start()這區塊使用緩衝ob_start()跟ob_end_flush() 但是最後還是出現一樣的錯誤 不知道是不是我的緩衝使用錯誤... 而爬文後也找到程式砍掉文件內的bom了 php.ini也修改過了=>info.php顯示output_buffering的值為1 伺服器也重開過了 另外google過一些資料發現也有些人有相同情況 有些回答的人指出 網頁頂端這行<?php virtual('/Connections/ezchange.php'); ?> 可能會有輸出的動作造成底下header的執行出錯 也試過將ob放在不同地方,但是有時候測試一出錯整個伺服器就掛掉需要重啟 以下是程式碼的部份...不知道到底是哪裡有問題呢? <?php virtual('/Connections/ezchange.php'); ?> <?php ob_start();?><?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } ?> <?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['mem_id'])) { $loginUsername=$_POST['mem_id']; $password=$_POST['mem_pass']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "/mem_home.php"; $MM_redirectLoginFailed = "/login_fail.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_ezchange, $ezchange); $LoginRS__query=sprintf("SELECT mem_no, mem_id FROM member WHERE mem_no=%s AND mem_id=%s", GetSQLValueString($loginUsername, "int"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $ezchange) 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 ); } } ?><?php ob_end_flush();?> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.126.170.195

10/06 05:07, , 1F
程式碼只有這些? 坦白說,我看不出來為何要用緩衝...
10/06 05:07, 1F

10/06 08:21, , 2F
output_buffering改4096,或是原文件有BOM需要移除
10/06 08:21, 2F

10/06 08:55, , 3F
我猜八成是BOM...
10/06 08:55, 3F
補完整一點...BOM我應該有用爬文的方法砍了說 再次執行他都會顯示找不到含有BOM的文件... ※ 編輯: ilovewr 來自: 122.126.170.195 (10/06 17:27)

10/06 19:03, , 4F
/Connections/ezchange.php 究竟有沒有輸出?
10/06 19:03, 4F

10/06 19:24, , 5F
output_buffering改4096了嗎?
10/06 19:24, 5F

10/08 05:45, , 6F
有改4096然後重啟了...結果一開那個網頁伺服器就會掛掉
10/08 05:45, 6F
文章代碼(AID): #1AoYHtw_ (PHP)
文章代碼(AID): #1AoYHtw_ (PHP)