เจอ Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by ครับ
error ที่ไฟล์ไหนครับ
Date :
2012-08-05 20:06:02
By :
hackerboy
ใส่ <?ob_start();?> ไว้บนสุดครับ
Date :
2012-08-05 21:08:06
By :
mr.win
Code ไฟล์ Index.php ครับ
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ThaiCreate.Com</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
@import url("js-css/style.css");
body {
background-image: url(images/bg.png);
background-color: #CCC;
}
</style>
</head>
<body>
<table width="60%" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center" id="header">
<!-- Menu -->
<? include("template/header.php"); ?>
</div>
</td>
</tr>
</table>
<table width="60%" align="center" cellpadding="0" cellspacing="0" class="box-1 mt">
<tr>
<td><div align="center" id="menu">
<!-- Menu -->
<? include("template/menu.php"); ?>
</div></td>
</tr>
<tr>
<td width="40%" align="center">
<!-- Container -->
<?
$page= $_REQUEST["page"];
SWITCH ($page){
case "home":
include("page/home.php");
break;
case "service":
include("page/service.php");
break;
case "product":
include("page/product.php");
break;
case "aboutus":
include("page/aboutus.php");
break;
case "contactus":
include("page/contactus.php");
break;
case "register":
include("register/register.php");
break;
case "register-save":
include("register/save_register.php");
break;
default:
include("page/home.php");
break;
}
?>
</td>
</tr>
<tr>
<td><div align="center" id="footer">
<!-- Footer -->
<? include("template/footer.php"); ?>
</div></td>
</tr>
</table>
</body>
</html>
และนี่
Code ไฟล์ register.php
<form name="form1" method="post" action="?page=register-save">
Register Form <br>
<table width="400" style="width: 400px">
<tbody>
<tr>
<td width="125"> Username</td>
<td width="180">
<input name="txtUsername" type="text" id="txtUsername" size="20">
</td>
</tr>
<tr>
<td> Password</td>
<td><input name="txtPassword" type="password" id="txtPassword">
</td>
</tr>
<tr>
<td> Confirm Password</td>
<td><input name="txtConPassword" type="password" id="txtConPassword">
</td>
</tr>
<tr>
</tr>
<tr>
<td> Email</td>
<td><input name="txtEmail" type="text" id="txtEmail" size="35"></td>
</tr>
<tr>
</tr>
</tbody>
</table>
<br>
<input type="submit" name="Submit" value="Save">
</form>
และนี่
Code ไฟล์ save_register.php ครับ
<?
session_start();
include('config/config.inc.php');
mysql_connect("$host","$user","$passwd") or die("ติดต่อ Host ไม่ได้");
mysql_select_db("$dbname") or die("ติดต่อ Database ไม่ได้");
if(trim($_POST["txtUsername"]) == "")
{
echo "Please input Username!";
exit();
}
if(trim($_POST["txtPassword"]) == "")
{
echo "Please input Password!";
exit();
}
if($_POST["txtPassword"] != $_POST["txtConPassword"])
{
echo "Password not Match!";
exit();
}
if(trim($_POST["txtEmail"]) == "")
{
echo "Please input Email!";
exit();
}
$strSQL = "SELECT * FROM $from WHERE playername = '".trim($_POST['txtUsername'])."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "Username already exists!";
}
else
{
$strSQL = "INSERT INTO $from (playername,password,Email,rang,SID,active) VALUES ('".$_POST["txtUsername"]."',
'".md5($_POST["txtPassword"])."','".$_POST["txtEmail"]."','USER','".session_id()."','0')";
$objQuery = mysql_query($strSQL);
$id = mysql_insert_id();
echo "Register Completed!<br>Please check your email to activate account";
$strTo = $_POST["txtEmail"];
$strSubject = "Activate Member Account";
$strHeader = "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
$strHeader .= "From: [email protected] \nReply-To: [email protected] ";
$strMessage = "";
$strMessage .= "Welcome : ".$_POST["txtUsername"]."<br>";
$strMessage .= "=================================<br>";
$strMessage .= "Activate account click here.<br>";
$strMessage .= "http://mc.xxxx.in.th/activate.php?sid=".session_id()."&id=".$id."<br>";
$strMessage .= "=================================<br>";
$strMessage .= "ThaiCreate.Com<br>";
$flgSend = mail($strTo,$strSubject,$strMessage,$strHeader);
}
mysql_close();
?>
ประวัติการแก้ไข 2012-08-05 22:55:49
Date :
2012-08-05 22:53:15
By :
pleum1129
ตอบให้แล้วครับ
Date :
2012-08-06 06:11:03
By :
mr.win
ลองดูพวก UTF-8 With BOM ด้วยครับ
Date :
2012-08-08 06:07:46
By :
mr.win
ผมใส่ <?ob_start();?> ไว้บนสุดของไฟล์ save_register.php ก็ไม่หายครับส่วน UTF-8 With BOM นี่ผมใช้ Notepad++ แปลงเป็น UTF-8 กับ UTF-8 With BOM ดูแล้วมันไม่เกิดไรขึ้นเลย บอกข้อมูลเพิ่มเติมครับ คือที่จริงมันขึ้นสองอันครับ
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/xxxx/domains/xxxx/public_html/mc/index.php:23) in /home/xxxx/domains/xxxx/public_html/mc/register/save_register.php on line 3
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/xxxx/domains/xxxx/public_html/mc/index.php:23) in /home/xxxx/domains/demolic_html/mc/register/save_register.php on line 3
Date :
2012-08-08 20:11:40
By :
pleum1129
Code (PHP)
<?ob_start();?>
<?
session_start();
include('config/config.inc.php');
mysql_connect("$host","$user","$passwd") or die("ติดต่อ Host ไม่ได้");
mysql_select_db("$dbname") or die("ติดต่อ Database ไม่ได้");
if(trim($_POST["txtUsername"]) == "")
{
echo "Please input Username!";
exit();
}
if(trim($_POST["txtPassword"]) == "")
{
echo "Please input Password!";
exit();
}
if($_POST["txtPassword"] != $_POST["txtConPassword"])
{
echo "Password not Match!";
exit();
}
if(trim($_POST["txtEmail"]) == "")
{
echo "Please input Email!";
exit();
}
$strSQL = "SELECT * FROM $from WHERE playername = '".trim($_POST['txtUsername'])."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "Username already exists!";
}
else
{
$strSQL = "INSERT INTO $from (playername,password,Email,rang,SID,active) VALUES ('".$_POST["txtUsername"]."',
'".md5($_POST["txtPassword"])."','".$_POST["txtEmail"]."','USER','".session_id()."','0')";
$objQuery = mysql_query($strSQL);
$id = mysql_insert_id();
echo "Register Completed!<br>Please check your email to activate account";
$strTo = $_POST["txtEmail"];
$strSubject = "Activate Member Account";
$strHeader = "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
$strHeader .= "From: [email protected] \nReply-To: [email protected] ";
$strMessage = "";
$strMessage .= "Welcome : ".$_POST["txtUsername"]."<br>";
$strMessage .= "=================================<br>";
$strMessage .= "Activate account click here.<br>";
$strMessage .= "http://mc.xxxx.in.th/activate.php?sid=".session_id()."&id=".$id."<br>";
$strMessage .= "=================================<br>";
$strMessage .= "ThaiCreate.Com<br>";
$flgSend = mail($strTo,$strSubject,$strMessage,$strHeader);
}
mysql_close();
?>
ลองดูครับ
Date :
2012-08-08 21:35:22
By :
mr.win
พี่วินเชค PM หน่อยครับ
Date :
2012-08-09 18:13:17
By :
pleum1129
ตอนนี้ผมได้ละผมลองเปลียนไฟล์ index.php ดูไม่รู้มันเกิดจากอะไร - - ก๊อบโค้ดไปวางไฟล์ใหม่แค่นั้นหายเลย
ขอบคุณมากครับ
ประวัติการแก้ไข 2012-08-09 20:47:34
Date :
2012-08-09 20:33:01
By :
pleum1129
Load balance : Server 04