|  | 
	                
  
    | 
	 
        ช่วยดูโค๊ดแชท ที่ครับทําไมมันขึ้นแบบนี้ครับ Warning: Cannot modify header information - headers already sent by (output started at ...     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\keng project music\chat\chatroom.inc.php:1) in C:\AppServ\www\keng project music\chat\index.php on line 40 
 index.php
 
 Code (PHP)
 
 <?php
session_start();
$errmsg = "";
if($_POST) {
	include("chatroom.inc.php");
	
	$name = $_POST['name'];
	if(empty($name)) {
		$errmsg = "กรุณากำหนดชื่อก่อนเข้าห้องสนทนา";
	}
	else if(has_rudeword($name)) {	//ตรวจสอบว่ามีคำหยาบอยู่ในชื่อหรือไม่
		$errmsg = "ไม่อนุญาตให้ใช้ชื่อที่ไม่เหมาะสม กรุณาแก้ไข";
	}
	else {	
		my_connect();		//เชื่อมต่อกับฐานข้อมูล
		
		//SQL ตรวจสอบว่ามีผู้ใช้ชื่อนั้นอยู่ก่อนแล้วหรือไม่
		$sql = "SELECT COUNT(*) FROM chatter WHERE name = '$name';";
	 	$result = mysql_query($sql);
		//ไม่อนุญาตให้ใช้ชื่อซ้ำกัน
		if(mysql_result($result, 0, 0) > 0) {
			$errmsg = "ชื่อ: $name มีผู้ใช้แล้ว กรุณาใช้ชื่อใหม่";
		}
		else {
			//ถ้าชื่อไม่ซ้ำ ให้เก็บชื่อนั้นในตาราง chatter
			//และเก็บข้อความที่แสดงว่ามีผู้เข้ามาในห้องสนทนาใหม่ในตาราง message
			$sql = "INSERT INTO chatter VALUES('$name', NOW(), NOW());";
			mysql_query($sql);
			$sql = "INSERT INTO message VALUES
				 		(0, '### $name', 'เข้าร่วมห้องสนทนา  ###', 'red', NOW());";
			mysql_query($sql);
			
			//สร้าง Session พักชื่อเอาไว้เพื่อนำไปใช้ในเพจ chatroom.php
			$_SESSION['name'] = $_POST['name'];
		
			//ย้ายการไปที่เพจ chatroom.php เพื่อเข้าสู่ห้องสนทนา
			header("Location: chatroom.php");
			exit;
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ห้องสนทนา: กำหนดชื่อ</title>
<link rel="stylesheet" href="../css/style.css"  />
<style type="text/css">
<!--
.style1 {font-size: 16px}
-->
</style>
</head>
<body>
<?php include("header.inc.html");		?>
<center>
<h3>กำหนดชื่อแทนตัว ก่อนเข้าสู่ห้องสนทนา:</h3>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];  ?>">
  
  <br />ชื่อ
    <input name="name" type="text" id="name" maxlength="30" />
    <input type="submit" name="Submit" value="ตกลง" />
</form>
<font color=red><b><?php echo $errmsg; ?></b></font>
</center>
</body>
</html>
 chatroom.php
 
 Code (PHP)
 
 <?php
session_start();
if(!isset($_SESSION['name'])) {
	header("Location: index.php");
	exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php  echo $_SESSION['name']; ?></title>
<link rel="stylesheet" href="../css/style.css"  />
<script src="../ajax/framework.js"></script>
<script>
function ajaxCall() {
	var data = getFormData("form1");
	var URL = "add_msg.php";
	ajaxLoad('post', URL, data, null);
	document.getElementById('msg').value = "";
}
//ฟังก์ชันสำหรับเมื่อคลิกปุ่มออกจากห้องสนทนา
function exitChatroom() {							
	if(!confirm('ออกจากห้องสนทนา ?')) {
		return;
	}
	var f = document.getElementById('form1');
	f.action = 'exit_chatroom.php';
	f.submit();
}
//ฟังก์ชันสำหรับตรวจสอบว่าคีย์ที่ผู้ใช้กดเป็นปุ่ม <Enter> หรือไม่
//หากใช่ให้ส่งข้อความออกไปเหมือนการคลิกที่ปุ่ม
function isPressEnter(event) {					
	if(event.keyCode == 13) {
		ajaxCall();
		return false;
	}
}
</script>
</head>
<body>
<?php 	include("header.inc.html");		?>
<table cellpadding="3" align="center">
<tr>
	<td width="550"><b>ห้องสนทนา</b></td><td width="200"><b>ผู้ร่วมสนทนา</b></td>
</tr>
<tr valign="top">
<td>
<iframe src="show_msg.html" width="550" height="300" 		
 	scrolling="yes"></iframe></td>
<td>
<iframe src="show_chatter.html" width="200" height="300" 
 	scrolling="yes"></iframe></td>
</tr>
<tr valign="top">
<td>
<form name="form1" id="form1" method="post" action="">
 
 ข้อความ:
<input type="text" id="msg" name="msg" size="55" maxlength="250"
	style="background-color:#ffffcc; "
	onkeypress="return isPressEnter(event)">
<input type="button" name="Button1" value="ส่ง" onclick="ajaxCall()" />
หรือ <Enter>	
<input type="hidden" name="name" 					
	value="<?php echo $_SESSION['name']; ?>" />
<br>
สีข้อความ:
<input type="radio" name="color" value="black" checked>ดำ
<input type="radio" name="color" value="red">แดง
<input type="radio" name="color" value="blue">น้ำเงิน
<input type="radio" name="color" value="green">เขียว
<input type="radio" name="color" value="orange">ส้ม
</form></td>
<td align="right">
<input type="button" name="Button2" value="ออกจากห้องสนทนา" onclick="exitChatroom()" />
</td>
</tr>
</table>
</body>
</html>
 
 
 Tag : PHP
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2010-12-17 15:59:58 | By :
                          kenghockey | View :
                          1308 | Reply :
                          6 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | error ฟ้องว่า ส่ง header ซ้ำ น่าจะเป็นตรง session มีตรงไหนซ้ำอีกเปล่าหว่า 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-12-17 16:03:46 | By :
                            mzchewiize |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ตามจริงมันเป็นtis-620 ผมเลย เซฟไฟล์ใหม่ให้เป็นutf-8 แล้วเอา with BOMออกแล้ว มันเลยเกิดปัญหาแบบนี้ขึ้นไม่เข้าใจ ถ้าเป็นtis-620 มันจะไม่มีปัญหาอ่ะครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-12-20 14:25:05 | By :
                            kenghockey |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ลองใส่ ob_start() ก่อน session_start() ดูครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-12-20 14:29:10 | By :
                            MAdmin |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | มันขึ้นแบบนี้อ่ะครับ 
 Parse error: syntax error, unexpected T_STRING in C:\AppServ\www\project27\index.php on line 3
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-12-23 16:36:09 | By :
                            kenghockey |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ใส่ ob_start(); แล้วก็ยังขึ้นครับ 
 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\project27\index.php:1) in C:\AppServ\www\project27\index.php on line 3
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-12-23 16:44:57 | By :
                            kenghockey |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |