Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > session เวลา run บน local server...Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by



 

session เวลา run บน local server...Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by

 



Topic : 027137



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์




ผมมีปัญหาเกี่ยวกับ session ครับ คือ เวลาผม test บน local server มันขึ้นแบบนี้น่ะครับ

Code
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\AppServ\www\nop_test\chkmember.php:8) in C:\AppServ\www\nop_test\chkmember.php on line 27

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\nop_test\chkmember.php:8) in C:\AppServ\www\nop_test\chkmember.php on line 27

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\nop_test\chkmember.php:8) in C:\AppServ\www\nop_test\chkmember.php on line 30


อย่าเข้าใจผิดน่ะครับ ว่าทำไมผมถึงไม่เช็คก่อน เพราะมีกระทู้แบบนี้เยอะแล้ว ผมเช็คแล้วครับจัดการแก้แล้วด้วย
ปัญหามันเกิดเฉพาะเวลาผม run บน local server เท่านั้น
พอเอา file upload ไปใช้บน free server กลับใช้ได้ปกติ ไม่ขึ้น error แต่อย่างไร ทั้งๆที่เป็น file เดียวกัน
คำถามผมคือ free server ที่ผมใช้กับ local server แตกต่างที่ตรงไหนครับ ผมต้องแก้ตรงไหนถึงจะสามารถ run file ได้เหมือน free server ครับ ช่วยแนะนำหน่อย ไม่อยากคอยไป test บน server ข้างนอกตลอดน่ะครับ

ขอบคุณล่วงหน้าครับ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-05-08 08:25:27 By : nopasurada View : 26322 Reply : 54
 

 

No. 1



โพสกระทู้ ( 913 )
บทความ ( 2 )



สถานะออฟไลน์
Facebook

chkmember.php

เอา file นี้มาดูหน่อยครับ






Date : 2009-05-08 10:07:20 By : teez1232002
 


 

No. 2



โพสกระทู้ ( 3,468 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter

php รุ่นไหนคับ
Date : 2009-05-08 10:36:47 By : pjgunner
 

 

No. 3



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


ckmember.php



Code (PHP)
<?php
$user_login=$_POST[user_login];
$pass_login=$_POST[pass_login];

if ($user_login=="" or $pass_login=="") {
	echo "<h3>ERROR : กรุณากรอกข้อมูล</h3>"; exit() ;
}
include "connect.php" ;
mysql_query("SET NAMES UTF8");
$sql="select * from tb_member where username = '$user_login' 
			and password = '$pass_login' " ;
$result = mysql_db_query ($dbname,$sql) ;
$num = mysql_num_rows ($result) ;
mysql_close() ;

if ($num <= 0) {
	echo "<h3>ERROR : Username หรือ Password ไม่ถูกต้อง</h3>" ;
}
else {
	session_start() ;
	$_SESSION[sess_userid]=session_id() ;
	$_SESSION[sess_username]=$user_login ;
	header("Location: main.php") ;
}
?>

Date : 2009-05-08 15:55:28 By : nopasurada
 


 

No. 4



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


php มันลงมาพร้อม appserv version 2.5.10 น่ะครับ เป็น php version 5.2.6
Date : 2009-05-08 15:57:35 By : nopasurada
 


 

No. 5



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


Code (PHP)
<?php
session_start() ;
$user_login=$_POST[user_login];
$pass_login=$_POST[pass_login];

if ($user_login=="" or $pass_login=="") {
    echo "<h3>ERROR : กรุณากรอกข้อมูล</h3>"; exit() ;
}
include "connect.php" ;
mysql_query("SET NAMES UTF8");
$sql="select * from tb_member where username = '$user_login' 
            and password = '$pass_login' " ;
$result = mysql_db_query ($dbname,$sql) ;
$num = mysql_num_rows ($result) ;
mysql_close() ;

if ($num <= 0) {
    echo "<h3>ERROR : Username หรือ Password ไม่ถูกต้อง</h3>" ;
}
else {
    $_SESSION[sess_userid]=session_id() ;
    $_SESSION[sess_username]=$user_login ;
    header("Location: main.php") ;
} 
?>


ที่ว่า error บน local แต่ไม่ error บน server นั้น server อาจปิดไม่ให้แสดง error ก็ได้
Date : 2009-05-08 16:57:28 By : plakrim
 


 

No. 6



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


ช่วยอธิบายเพิ่มเติมได้ไหมครับ ยังไม่ค่อยเข้าใจ
แล้ว code ที่ท่าน Prakrim แก้ให้ ผมลองแล้วก็ยังไม่ได้อะครับ รวมถึงเพิ่ม ob_start() แล้วครับ ไม่ได้ผล
แต่เท่าที่ผมลอง test กับ server ในเรื่องอื่นๆ มันแสดงผลเหมือนกันนะครับ หมายถึงถ้า error ในเรื่องอื่น
ผมเลยคิดว่ามันน่าจะมีอะไรที่แตกต่างกันระหว่าง local server กับ free server ที่ผมใช้อยู่ แต่ไม่รู้ว่าคืออะไร
Date : 2009-05-08 17:14:09 By : nopasurada
 


 

No. 7



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


ยังแก้ไม่ได้เลย มีใครรู้ ช่วยหน่อยครับ
Date : 2009-05-09 16:19:12 By : nopasurada
 


 

No. 8



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


<? บรรทัดแรกตรงนี้ห้ามมีอะไรเลยนะ เคาะวรรคก็ไม่ได้แท็บก็ไม่ได้
ob_start();
session_start();
Date : 2009-05-09 21:15:01 By : plakrim
 


 

No. 9



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


ลองแล้วครับ ยังไม่ได้

Code
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\AppServ\www\nop_test\chkmember.php:8) in C:\AppServ\www\nop_test\chkmember.php on line 10

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\nop_test\chkmember.php:8) in C:\AppServ\www\nop_test\chkmember.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\nop_test\chkmember.php:8) in C:\AppServ\www\nop_test\chkmember.php on line 31

line 10
session_start() ;

line 31
header("Location: main.php") ;

Date : 2009-05-09 22:31:02 By : nopasurada
 


 

No. 10



โพสกระทู้ ( 519 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ในไฟล์ "connect.php"
มี echo หรือ print อะไรออกมาหรือเปล่าคับ
จาก error มันบอกว่า
(output started at C:\AppServ\www\nop_test\chkmember.php:8)
คือหมายถึง เริ่มมีการแสดง output ตั้งแต่บรรทัดที่ 8 ซึ่งก็คือ include "connect.php";

ลองเอา connect.php มาดูกันคับ
Date : 2009-05-09 22:53:46 By : nut_t02
 


 

No. 11



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


connect.php


Code (PHP)
<?php
$host = "localhost";
$user = "root";
$pw = "nop";
$dbname = "db_member";
$c = mysql_connect($host,$user,$pw);
if (!$c) {
	echo "<h3>ERROR : ไม่สามารถติดต่อฐานข้อมูลได้</h3>";
	exit();
}
?>

Date : 2009-05-09 23:03:01 By : nopasurada
 


 

No. 12



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


Code (PHP)
<?php
include "connect.php" ;
mysql_query("SET NAMES UTF8"); 
?>


จากข้างบน มาต่อกันได้แบบนี้

Code (PHP)
<?php
$host = "localhost";
$user = "root";
$pw = "nop";
$dbname = "db_member";
$c = mysql_connect($host,$user,$pw);
if (!$c) {
    echo "<h3>ERROR : ไม่สามารถติดต่อฐานข้อมูลได้</h3>";
    exit();
}
mysql_query("SET NAMES UTF8"); 
?>


ผมยังไม่เห็น select db เลย มันคง มีการฟ้อง error ตรง mysql_query("SET NAMES UTF8"); ทำให้เกิด output ก่อน start session ปัญหาน่าจะอยู่ตรงนี้แล
Date : 2009-05-10 00:50:39 By : plakrim
 


 

No. 13

Guest


ผมเจอปัญหาเดียวกันครับ ผมลองลบ cookie แล้วรันใหม่ ใส่ ob_start(); ผ่านแล้วครับ พี่ PlaKriM พอดีผ่านมาเจอ ปัญหาเดียวกัน ขอบคุณครับ สุทัศน์
Date : 2009-05-10 00:59:03 By : สุทัศน์
 


 

No. 14



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


ทุกคนขอบคุณนะครับ แต่ผมก็ยังแก้ไม่ได้อะครับ
code ล่าสุด แก้ตามที่คุณ Prakrim แนะนำนะครับ น่าจะใช่นะครับ ถ้าไม่ใช่บอกหน่อยนะครับ เดี๋ยวจะได้แก้แล้วลองอีกที

Code (PHP)
<?php
ob_start();
session_start();
$user_login=$_POST[user_login];
$pass_login=$_POST[pass_login];

if ($user_login=="" or $pass_login=="") {
	echo "<h3>ERROR : กรุณากรอกข้อมูล</h3>"; exit() ;
}
include "connect.php" ;

$sql="select * from tb_member where username = '$user_login' 
			and password = '$pass_login' " ;
$result = mysql_db_query ($dbname,$sql) ;
mysql_query("SET NAMES UTF8");
$num = mysql_num_rows ($result) ;
mysql_close() ;

if ($num <= 0) {
	echo "<h3>ERROR : Username หรือ Password ไม่ถูกต้อง</h3>" ;
}
else {
	
	$_SESSION[sess_userid]=session_id() ;
	$_SESSION[sess_username]=$user_login ;
	header("Location: main.php") ;
}
?>



แล้วก็ทำการ delete cookie เรียบร้อย แล้วนะครับ แต่ยังคงไม่ได้ มันขึ้นแบบนี้ครับ

Code
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\AppServ\www\nop_test\chkmember.php:8) in C:\AppServ\www\nop_test\chkmember.php on line 10

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\nop_test\chkmember.php:8) in C:\AppServ\www\nop_test\chkmember.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\nop_test\chkmember.php:8) in C:\AppServ\www\nop_test\chkmember.php on line 32

line 10
session_start();

line 32
header("Location: main.php") ;

Date : 2009-05-10 01:26:52 By : nopasurada
 


 

No. 15



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


line 10
session_start();
ก็แสดงว่ามีอะไรก่อน session_start(); ? นี่คือโค๊ดทั้งหมดแล้วหรือ
Date : 2009-05-10 01:39:25 By : plakrim
 


 

No. 16



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


ใช่ครับ นี่เป็นส่วนของ code ทั้งหมดแล้วครับ ที่อยู่ข้างบน บนพวก title html น่ะครับ

Code
<!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>Untitled Document</title>
</head>
<body>
<?php

Date : 2009-05-10 02:04:18 By : nopasurada
 


 

No. 17



โพสกระทู้ ( 22 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

อาจมีหลายสาเหตุนะครับพี่น้องที่ผมเจอนะครับ
1. มีการเขียนคำสั่งหรือค่าอะไรต่างๆ ก่อน session_start(); ไอ้ตัวนี้ต้องอยู่บนสุดเสมอ
2. Server ที่เราใช้อยู่อาจปิดการใช้ register_globals = Off (ดูที่ไฟล์ php.ini ในโฟลเดอร์ windows บรรทัดที่ 380) ซึ่งถ้ามีการปิด (ปกติ register_globals = On) การส่งค่าต่างๆ จะต้องมีการประการตัวแปรรับ/ส่งค่าให้ถูกต้องตามหลักไวยากรณ์
3. ถ้าเป็น Server Free ส่วนใหญ่จะปิด Register_Globals ครับ

ดังนั้นการแก้ไขแนะนำให้ตรวจสอบว่า
- การรับส่งค่าต่างๆ เราได้สร้างตัวแปรรับส่งหรือไม่
- ต้องเขียนให้ถูกหลักการครับ

ตัวอย่าง
ถ้า register_globals = On
ที่ไฟล์ A.php เราส่งค่าไปให้ไฟล์ B.php เช่น B.php?data=123
ที่ไฟล์ B.php เราสามารถใช้คำสั่ง echo $data; แสดงค่า 123 ได้เลยครบ
แต่ถ้า register_globals = Off
เราต้องรับค่าโดย $data=$_REQUEST['data']; ก่อนจึงจะสามารถใช้งานได้

==================================
ปัญหาดังกว่าผมก็เคยเจอครับ ซึ่งต้องขอคำแนะนำจากผู้ให้บริหาร Server ด้วยจะทำให้เราแก้ไขได้เร็วกว่า

ผมใช้ WM Server 3.0 ในการเขียน PHP ครับ (รับบน Vista) ใช้มานานแล้วยังไม่เคยงอแงครับ ผมว่า Server ตัวนี้ใช้งาน และเบาดีด้วย ติดตั้งง่าย ใช้ดีทีเดียว


ด้วยความนับถือ
Date : 2009-05-10 02:06:52 By : mrsitti
 


 

No. 18



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


Code
ใช่ครับ นี่เป็นส่วนของ code ทั้งหมดแล้วครับ ที่อยู่ข้างบน บนพวก title html น่ะครับ

<!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>Untitled Document</title>
</head>
<body>
<?php


โอ้โห พี่น้องครับ ให้งมกันมาหลาย rep

น้องย้ายตูด
ob_start();
session_start();
ไปไว้นี่เลย ก่อน <!DOCTYPE อะครับ

Code
<?
ob_start();
session_start();
?>
<!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>Untitled Document</title>
</head>
<body>
<?php
$user_login=$_POST[user_login];
$pass_login=$_POST[pass_login];


การ start session ห้ามมี output ก่อน ไอ้ <!DOCTYPE .....จนถึง...... <body> นั่นแหละ output กำของเวน
Date : 2009-05-10 02:30:58 By : plakrim
 


 

No. 19



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


โอ้โห ขอบคุณครับ ได้แล้ว แต่ยังมีปัญหาต่อมาครับ เศร้า

มัน run หน้า main.php ขึ้นมาได้นะครับ แต่มีอันนี้มาด้วยอะดิ แก้ไงอะ

Code
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\nop_test\main.php:9) in C:\AppServ\www\nop_test\chksession.php on line 3


chksession.php on line 3 คือ session_start(); ผมเอาไปไว้ด้านบนสุดเลยครับตามที่พี่ plakrim แนะนำ


สุดท้ายครับ สงสัยอย่างแรงครับว่า ทำไม free server ที่ใช้ สามารถ runได้ไม่มีปัญหาเลย ไม่ว่าจะเปลี่ยน
register_globals เป็น off หรือ on แสดงว่าไม่น่าจะเป็นที่การรับค่า(มั้งนะ) แล้วก็ไม่จำเป็นต้อง เอา session_start() ไว้ด้านบนด้วย แต่ทำไม local server run แล้วเกิดปัญหาทั้งๆที่เป็น file เดียวกัน งงสุดๆ
อีกอย่าง code ผมก็เลียนแบบมาจากหนังสือ เป็นไปได้ไหมครับ ว่าเป็นที่ local server เราเองที่เป็นปัญหา
Date : 2009-05-10 03:09:20 By : nopasurada
 


 

No. 20



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


main.php
มีการ start session แล้วไม่ต้อง start ซ้ำในไฟล์ chksession.php
ถ้าพี่เดาไม่ผิด start มันทั้งสองไฟล์ใช่ไหม



ส่วนเรื่องที่งง ไม่ต้องงงหรอก เพราะมันคง config ไม่เหมือนกัน สภาพแวดล้อมที่ต่างกัน และเดาว่า free server อาจปิดไม่ได้แสดง error ลองใส่
ob_start();
session_start();
error_reporting(E_ALL & ~E_NOTICE); // ตรงนี้ใส่เพิ่มเข้ามา
Date : 2009-05-10 03:22:55 By : plakrim
 


 

No. 21

Guest


พี่ Plakrim ครับ ถ้าลองเอา session_start(); มันจะ error ครับ แล้วก็ไม่แสดงหน้า main.php ครับ

Code
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\nop_test\main.php:9) in C:\AppServ\www\nop_test\chksession.php on line 13


line 13
header("Location: index.html") ;

แต่ถ้าใส่ session_start(); ไม่ว่าตำแหน่งบนสุดหรือไม่ก็แสดง หน้า main.php ได้ปกติครับ แต่มันจะฟ้อง error ด้วยที่ บรรทัด session_start(); ครับ

ปล.ผมทดลองใส่ ob_start() แล้ว ใส่หรือไม่ ผลก็ไม่แตกต่างครับ

Code
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\nop_test\main.php:9) in C:\AppServ\www\nop_test\chksession.php on line 2


Code (PHP)
<?php
session_start();
?>
<!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>Untitled Document</title>
</head>

<body>
<?php
$sess_userid=$_SESSION[sess_userid] ;
$sess_username=$_SESSION[sess_username] ;
if ($sess_userid<>session_id() or $sess_username=="" ) {
	header("Location: index.html") ;
	exit() ;
}
?>

Date : 2009-05-10 21:11:06 By : nopasurada
 


 

No. 22



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


รบกวนเอาโค๊ดหน้า
main.php, chksession.php
ทั้งหมดมาดูด้วยครับ ทำไมมันลำบากจัง

จะใช้ header ก็ต้องใส่ ob_start ครับ
Date : 2009-05-10 21:23:02 By : plakrim
 


 

No. 23



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


main.php

Code (PHP)
<!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>Member ระบบสมาชิก</title>
</head>

<body>
<?php
include "chksession.php" ;
?>
<h1>:: Logined In System ::</h1>
<p>ยินดีต้อนรับ<b><?=$sess_username?></b>ท่านกำลังอยู่ในระบบสมาชิก</p>
<p> [<a href="edit.php">แก้ไขข้อมูลส่วนตัว</a> ]
		[ <a href="changepw.php">เปลี่ยนรหัสผ่าน</a> ]
		[ <a href="logout.php">ออกจากระบบ</a></p>
</body>
</html>
?>

Date : 2009-05-10 23:06:13 By : nopasurada
 


 

No. 24



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


chksession.php

Code (PHP)
<?
ob_start();
session_start();
?>
<!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>Untitled Document</title>
</head>

<body>
<?php
$sess_userid=$_SESSION[sess_userid] ;
$sess_username=$_SESSION[sess_username] ;
if ($sess_userid<>session_id() or $sess_username=="" ) {
	header("Location: index.html") ;
	exit() ;
}
?>
</body>
</html>

Date : 2009-05-10 23:07:30 By : nopasurada
 


 

No. 25



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


Code
<?
ob_start();
session_start();
?>

<!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>Member ระบบสมาชิก</title>
</head>

<body>
<?php
$sess_userid=$_SESSION[sess_userid] ;
$sess_username=$_SESSION[sess_username] ;
if ($sess_userid<>session_id() or $sess_username=="" ) {
header("Location: index.html") ;
exit() ;
}
?>

<h1>:: Logined In System ::</h1>
<p>ยินดีต้อนรับ<b><?=$sess_username?></b>ท่านกำลังอยู่ในระบบสมาชิก</p>
<p> [<a href="edit.php">แก้ไขข้อมูลส่วนตัว</a> ]
[ <a href="changepw.php">เปลี่ยนรหัสผ่าน</a> ]
[ <a href="logout.php">ออกจากระบบ</a></p>
</body>
</html>
?>


ไปทำความเข้าใจเรื่อง include require หน่อยนะครับ

ถ้าอยาก include เอาแค่ตัวหนาตรงกลาง ไปสร้างไฟล์ chksession.php
Date : 2009-05-10 23:11:38 By : plakrim
 


 

No. 26

Guest


พี่ plakrim ครับ ผมทดลองทำตามที่พี่แนะนำแล้วนะครับ

1.เอาเฉพาะตัวหนาไปทำ file chksession.php (ลบ title ออกหมดแล้วนะครับ)
-->ผลไม่แตกต่าง
2.เรื่อง include กับ require ผมพอจะเคยอ่านบทความมานิดหน่อยใน web นี้แหละครับ พอจะจับใจความได้ว่า include ถ้า error ก็ข้ามไปทำ step อื่นต่อได้ แต่ require ถ้า error จะหยุดทันที เหมือนกับว่า ถ้าไม่ได้ตัวแปรจาก require มาก็จะไม่สามารถประมวลผลหน้าต่อไปได้ ถ้าจะให้เปรียบกับภาษาอังกฤษก็น่าจะเหมือน want กับ need
ไม่รู้ผมเข้าใจถูกรึเปล่านะ
3.ลองเอา code
ob_start();
session_start();
error_reporting(E_ALL & ~E_NOTICE); // ตรงนี้ใส่เพิ่มเข้ามา

ไปใส่ใน file ที่อยู่ใน free server แต่ไม่แสดง error อะไรออกมาเลย สรุปน่าจะเป็นที่ config ของ server ตามที่พี่บอกจิงๆ
แต่ไม่รู้ว่าแตกต่างไงนี่สิ เซ็งเลย

ปล.อย่าเพิ่งเซ็งผมนะ แค่ปัญหาผมเยอะกว่าชาวบ้านนิดหน่อย อิอิอิ ถ้ามีโอกาสเดี๋ยวพาไปเลี้ยงข้าวตอบแทน อิอิอิ
Date : 2009-05-11 00:01:50 By : nopasurada
 


 

No. 27



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


Code
<?
ob_start();
session_start();
?>
<!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>Member ระบบสมาชิก</title>
</head>

<body>
<?
$sess_userid=$_SESSION[sess_userid] ;
$sess_username=$_SESSION[sess_username] ;
if ($sess_userid<>session_id() or $sess_username=="" ) {
header("Location: index.html") ;
exit() ;
}
?>
<h1>:: Logined In System ::</h1>
<p>ยินดีต้อนรับ<b><?=$sess_username?></b>ท่านกำลังอยู่ในระบบสมาชิก</p>
<p> [<a href="edit.php">แก้ไขข้อมูลส่วนตัว</a> ]
[ <a href="changepw.php">เปลี่ยนรหัสผ่าน</a> ]
[ <a href="logout.php">ออกจากระบบ</a></p>
</body>
</html>


แล้วถ้าเอานี่ไปรันดูมี error อะไรไหม
Date : 2009-05-11 00:09:41 By : plakrim
 


 

No. 28



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


ลอง run ดูแล้วครับ ไม่มี error แล้วครับ
สงสัยจังว่ามันแต่ต่างกันยังไงครับ ระหว่างใส่ code ไปเลย กับแยก code ไปอีกหน้านึง แล้วใช้ include ดึงมา ทั้งๆที่เป็น code ชุดเดียว แต่ผลออกมาไม่เหมือนกัน
Date : 2009-05-11 22:28:34 By : nopasurada
 


 

No. 29



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


คุณอาจเขียนอะไรผิดนิดหน่อยมั้ง ผิดในไฟล์ที่ include มานั่นแหละ
Date : 2009-05-11 22:33:56 By : plakrim
 


 

No. 30



โพสกระทู้ ( 519 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


มหากาพย์จิงๆ
แหะๆ


Date : 2009-05-11 23:08:36 By : nut_t02
 


 

No. 31

Guest


php.ini

000000 หาเอา เนอะ!!!

outputbuff_*** =จาก off เป็น on!!!!
Date : 2009-05-31 14:02:52 By : 555
 


 

No. 32

Guest


สุดยอดมากเลยครับได้แย้วขอบคุณนะ
Date : 2009-08-20 10:24:59 By : bestict
 


 

No. 33



โพสกระทู้ ( 126 )
บทความ ( 0 )



สถานะออฟไลน์


session_register ยังอ่ะครับ

session_register("var");
Date : 2010-07-13 08:26:59 By : kanjero
 


 

No. 34



โพสกระทู้ ( 60 )
บทความ ( 0 )



สถานะออฟไลน์


Code
@session_start();
ใส่นำหน้าก็ได้ ครับ
เคยอ่านเจอ ใน thaicreate นี่แหละครับ ใช่ได้ เหมือนกัน

Date : 2010-07-13 15:18:03 By : juder
 


 

No. 35



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ใส่ @ ไม่ได้น่ะครับ มันทำงานได้จริง แต่ session ไม่สามารถใช้งานได้ครับ

ลองวิธีนี้น่ะครับ

เปิดไฟล์ด้วย notepad แล้วแก้ให้เป็น ANSI


ANSI & UTF-8
Date : 2010-07-13 18:09:55 By : webmaster
 


 

No. 36

Guest


รันบน local ได้ แต่พออัพขึ้น server กลับไม่ได้ error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

เป็นหน้าแสดงข้อมูล และทำการแก้ไขข้อมูลของสมาชิกค่ะ


include("config.inc.php");
if(isset($_GET[cusid])){
$sql = "select * from customer c JOIN province p ON c.prov_id=p.prov_id where Cus_id=$_GET[cusid]";
$result = mysql_query($sql);
$data = mysql_fetch_array($result);-------------->ติดบรรทัดนี้ค่ะ

แล้วแบบนี้หละค่ะ คุณพี่PlaKriM
Date : 2010-08-11 17:13:25 By : boomy
 


 

No. 37



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
php.ini

000000 หาเอา เนอะ!!!

outputbuff_*** =จาก off เป็น on!!!!



ตอนใช้งานบน Server จริง ๆ มันจะมีปัญหาน่ะครับ
Date : 2010-08-11 17:30:43 By : webmaster
 


 

No. 38

Guest


พี่ mr.win อธิบายอีกได้ไหมค่ะ ไม่ทราบจริงๆๆค่ะ ขอบคุณค่ะ
Date : 2010-08-11 17:38:30 By : boomy
 


 

No. 39



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

บางครั้งเขียนด้วย Dreamweaver มันจะมีอักษรแปลก ๆ อยู่ข้างหน้าคำสั่งในส่วนของ line แรก ซึ่งเราจะมองไม่เห็น และจะต้องเปิดด้วย Edit Plus หรือ Notepad ครับ


Cannot send session cookie



Cannot send session cookie



Cannot send session cookie


เลือก Type ที่จะ Save ให้ถูกต้องครับ


Go to : session เวลา run บน local server...Warning: session_start() function.session-start: Cannot send session cookie - headers already sent by
Date : 2010-09-15 08:28:52 By : webmaster
 


 

No. 40



โพสกระทู้ ( 6 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook Hi5 Blogger

เวลาเซฟ ก็ให้เปลี่ยน การเข้ารหัสไฟล์ใหม่ จาก UTF-8 >> TIS-620 ลองดูนะครับ
Date : 2010-12-14 21:25:27 By : pongpatkku
 


 

No. 41



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


Quote:
เวลาเซฟ ก็ให้เปลี่ยน การเข้ารหัสไฟล์ใหม่ จาก UTF-8 >> TIS-620 ลองดูนะครับ


ไม่ใช่วิธีแก้ปัญหาครับ
Date : 2010-12-15 00:40:41 By : PlaKriM
 


 

No. 42



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Go to : Warning: Cannot modify header information - headers already sent by
Date : 2011-02-27 06:40:43 By : webmaster
 


 

No. 43



โพสกระทู้ ( 187 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ขอบคุณมากค่ะ
Date : 2011-12-06 22:40:10 By : banana_bnn
 


 

No. 44

Guest


ขอบคุณความเห็นที่ NO.35 มากๆ เลยค่ะ~
Date : 2011-12-21 01:36:31 By : REFICUL
 


 

No. 45

Guest


ขอบคุณทุกคำแนะนำครับ
Date : 2011-12-30 15:58:52 By : nara
 


 

No. 46

Guest


ถ้า encode UTF8 ต้อง without BOM ครับ
ใช้ notepad++ เปลี่ยนได้ครับ
Date : 2012-01-09 15:01:46 By : TTT
 


 

No. 47

Guest


ขอบคุณความรู้ดีดีค่ะ ลองอ่านแล้วแก้ตามทำได้เลย
Date : 2012-01-12 14:58:32 By : poon
 


 

No. 48



โพสกระทู้ ( 12 )
บทความ ( 0 )



สถานะออฟไลน์


อ๊ะ ผมก็ได้แล้ว แก้โดยการ Save เป็น utf-8 with out BOM หายขาด
ตอนแรก เซฟเป็น ANSI รันดู character เอ๋อไปเลย
Date : 2012-03-02 15:56:42 By : grart
 


 

No. 49

Guest


ขอบคุณครับ ผมทำได้แล้วแย้ๆๆ ผมใช้ notepad เปลี่ยนเป็น ANSI
Date : 2012-04-25 02:02:25 By : เด็กลองของ
 


 

No. 50



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์


ปัญหาเดี๋ยวกันครับที่เจอ

Code
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\newweb\zodiac\admin\connect\connect.php:12) in C:\AppServ\www\newweb\zodiac\admin\login.php on line 9


ผมจะส่งโค้ดไปให้ ช่วยตรวจดูให้ทีนะครับ ผมทำแล้วจนด้วยเกล้าจริงๆ

Code (PHP)
<?
session_start();
if (session_is_registered("valid_uname")) {
}
require("connect/connect.php");
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<title>::: หจก.โซดิแอคคอมพิวเตอร์ :::</title>
<link href="css/styles.css" rel="stylesheet" type="text/css">
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<style type="text/css">
<!--
.style1 {font-family: Tahoma}
.style2 {font-family: Tahoma; font-size: 12px; }
-->
</style>
</head>
<body topmargin="0">
<table width="778" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
  <tr> 
    <td bgcolor="#FFFFFF"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td><?php require_once('head.php'); ?></td>
        </tr>
        <tr> 
          <td><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#f2f2f6" bgcolor="#FFFFFF">
              <tr> 
                <td width="23%" valign="top"><?php 
				require_once('menuleft.php'); 
				?><br>
                  <br>
                  <p><br>
                  </p>
                    <p>&nbsp;</p></td><td width="54%" valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <!--DWLayoutTable-->
                    <tr> 
                      <td width="417" height="24" valign="top"><div align="center"> 
                          <table width="100%" border="0" cellspacing="2" cellpadding="2">
                            <tr> 
                              <td height="15" valign="top"> <div align="left"><img src="image/promote.jpg" width="432" height="266"></div></td>
                            </tr>
                          </table>
                        </div></td>
                    </tr>
                    <tr> 
                      <td height="310" valign="top">
<table width="415" border="0">
                          <tr>
                            <td><hr width="96%" color="#f2f2f6"></td>
                          </tr>
                          <tr> 
                            <td> 
                              <table width="421" height="22" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
                                <tr> 
                                  <td width="8"> <img src="image/menu01.jpg" width="8" height="22" alt=""></td>
                                  <td width="389" background="image/menu02.jpg"><div align="center" class="style1"><strong>สินค้าเข้ามาใหม่</strong></div></td>
                                  <td width="9"> <img src="image/menu03.jpg" width="9" height="22" alt=""></td>
                                </tr>
                              </table></td>
                          </tr>
                          <tr> 
                            <td><table width="99%" border="0" align="center">
                              <tr>
                                <td width="18%" background="image/menu02.jpg" bgcolor="#006600"><div align="center" class="style2">รหัสสินค้า</div></td>
                                <td width="40%" background="image/menu02.jpg" bgcolor="#006600"><div align="center" class="style2">ชื่อสินค้า</div></td>
                                <td width="16%" background="image/menu02.jpg" bgcolor="#006600"><div align="center" class="style2">จำนวนสินค้า</div></td>
                                <td width="17%" background="image/menu02.jpg" bgcolor="#006600"><div align="center" class="style2">ราคาสินค้า</div></td>
                              </tr>
                              <?php
		$sql="select * from products ORDER BY `prod_id` DESC LIMIT 0,5 ";
		$result=mysql_query($sql,$conn);
		while($data=mysql_fetch_array($result)){
	?>
                              <tr>
                                <td background="image/img2.jpg" bgcolor="#FFCC33"><div align="center" class="style2"><? echo "<a href=\"product_view.php?ProductID=$data[prod_id]\">$data[prod_id] </a>\n"; ?></div></td>
                                <td background="image/img2.jpg" bgcolor="#FFCC33"><div align="center" class="style2"><? echo $data['prod_name']; ?></div></td>
                                <td background="image/img2.jpg" bgcolor="#FFCC33"><div align="center" class="style2"><? echo $data['prod_total']; ?></div></td>
                                <td background="image/img2.jpg" bgcolor="#FFCC33"><div align="center" class="style2"><?php echo number_format($data[prod_price],0,'.',',')?></div></td>
                              </tr>
                              <?php } ?>
                            </table></td>
                          </tr>
                          <tr> 
                            <td width="378"><p align="center">&nbsp;</p>
                            <p>&nbsp;</p>
                            <p>&nbsp;  </p></td>
                          </tr>
                        </table>
                        <hr width="96%" color="#f2f2f6">
                        <p>&nbsp;</p>                      </td>
                    </tr>
                  </table></td>
                <td width="23%" valign="top"><?php require_once('menuright.php'); ?></td>
              </tr>
              <tr> 
                <td colspan="3" valign="top">
                  <?php require_once('down.php'); ?>                </td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>


หากต้องการทั้งชุดผมส่งให้ครับ
Date : 2012-06-03 12:55:21 By : pai
 


 

No. 51



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์


และตัวอย่างที่เป็นปัญหาครับ (ต่อ)

Code (PHP)
<?
ob_start();
session_start();
session_destroy();
?><head>
<title>..:: ระบบจัดการฐานข้อมูล ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
</head>

<link rel="stylesheet" href="../css/styles.css" type="text/css">
<body bgcolor="#FFFFFF">
<br>
<TABLE cellSpacing=1 cellPadding=4 width="39%" bgColor=#000000 border=0 align="center" height="190">
  <TBODY> 
  <TR> 
    <TD height="5" bgcolor="#FFFFFF"> 
      <div align="center"><b><font face="MS Sans Serif" size="-2">Admin Login</font></b></div>
      </TD>
  </TR>
  <TR bgcolor="#FFFFFF"> 
    <TD height="5"> <br>
      <form name="form1" method="post" action="login.php">
        <table width="100%" border="0" cellspacing="2" cellpadding="2">
          <tr> 
            <td width="16%">&nbsp;</td>
            <td width="20%"><font face="MS Sans Serif" size="-2">User</font></td>
            <td width="64%"><input name="txtlogin" type="text" id="txtlogin"></td>
          </tr>
          <tr> 
            <td width="16%">&nbsp;</td>
            <td width="20%"><font face="MS Sans Serif" size="-2">Password</font></td>
            <td width="64%"><input name="txtpasswd" type="password" id="txtpasswd"></td>
          </tr>
          <tr> 
            <td width="16%">&nbsp;</td>
            <td width="20%"><font face="MS Sans Serif" size="-2">&nbsp;</font></td>
            <td width="64%"><font face="MS Sans Serif" size="-2">&nbsp;</font></td>
          </tr>
          <tr> 
            <td width="16%">&nbsp;</td>
            <td width="20%"><font face="MS Sans Serif" size="-2">&nbsp;</font></td>
            <td width="64%"> <font face="MS Sans Serif" size="-2"> 
              <input type="submit" name="Submit" value="ล็อกอิน" class="button">
              <input name="Reset" type=reset class=button onClick="javascript:location='../index.php'"  value="ยกเลิก">
              </font></td>
          </tr>
        </table>
        <br>
      </form>
      </TD>
  </TR>
  </TBODY> 
</TABLE>
<br>
<br>

Date : 2012-06-03 12:57:46 By : pai
 


 

No. 52

Guest


พอดีเจอปัญหาแบบนี้อยู่ ขอบคุณมากนะค้ะ กระทู้นี้มีประโยชน์มากค้ะ
Date : 2013-01-29 11:07:37 By : pookpuy
 


 

No. 53

Guest


เท่าที่ลองดู เอา session_start(); ใส่ไว้ก่อน หรือใน <head></head> ก็ใช้ได้แล้วนี่ มันก็บอกอยู่ headers already sent
Date : 2013-07-20 05:34:55 By : hAndIcAp
 


 

No. 54



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

เซฟ UTF-8 without BOM หายจริงๆ
Date : 2013-10-21 06:31:02 By : verture
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : session เวลา run บน local server...Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่