[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 370: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5312: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3925)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5312: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3925)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5312: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3925)
[PHP] วิธีใช้ session - ออกแบบเว็บไซต์ ออกแบบสื่อสิ่งพิมพ์ : F6D Webboard

[PHP] วิธีใช้ session

แจก JavaScript, phpTip, XML, JavaTip, Vector, Fonts, icons, PSD etc...
kij
Administrator
Administrator
โพสต์: 6
ลงทะเบียนเมื่อ: ศุกร์ 09 ก.ค. 2010 3:34 am
ติดต่อ:

[PHP] วิธีใช้ session

โพสต์โดย kij » เสาร์ 31 ก.ค. 2010 1:30 am

ตัวแปร session จะเป็นตัวแปรพิเศษ ที่จะเก็บข้อมูลฝั่ง Server โดยสามารถใช้ได้ทุกหน้า webpage
แต่เมื่อเราปิดหน้าเวป ตัวแปร session นั้น ๆ จะหมดหยุดการทำงานทันที่(หยุดเวลาการทำงาน)


วิธีใช้ session จะต้องเขียน

session_start();
$_SESSION['session_name'] = 'AAA';

จำเป็นที่จะต้อง ใช้ function session_start(); ก่อนเสมอ ไม่เช่นนั้นจะไม่สามารถใช้ session ได้

เนื่องจาก session เป็นตัวแปรที่จะปิดตัวเอง เมื่อปิดเวปเพจ งงไหม ? (กล่าวคือ เมื่อเราประกาศ session เวลาในการทำงาน เมื่อเราหยุด การทำงานหรือเปลี่ยนหน้าจอ session นั้นก็จะหยุดการทำงานลง ประมาณนี้)

ส่วนถามว่า session ? คืออะไร

จะตอบแบบง่ายๆ ก็คือ การเก็บค่า จาก Web Server ลงในหน่วยความจำของเครื่อง
Client แต่ละราย server จะกำหนดเวลาและติดตามการใช้งานของเครื่อง Client

แต่ถ้าเราต้องการหยุดเวลาให้กับ session ก็สามารถทำได้โดย

session_set_cookie_params(time() + 86400, 'session_path', 'domain');
session_start();
$_SESSION['session_name'] = 'AAA';

Session ID คืออะไร

Session ID คือ หมายเลขประจำตัว
ที่ Web Server ส่งมายัง Client ค่า Session จะไม่มีทางซ้ำกัน Session ID
มีประโยชน์ในการอ้างอิงเกี่ยวกับการใช้งานของ Client

รูปแบบการอ่านค่า Session ID
Session_ID();

// เพิ่มเติม //

การสร้าง session

Session_Start()
$name=value;
Session_regis("name");


การอ่านค่าจาก Session

Session_Start();
$name;
echo"$name";


การตรวจสอบตัวแปร Session

Session_Start();
$name;
if(Session_is_registered("$name"))
{
echo"ตัวแปรนี้มีค่าอยู่";
}
else
{
echo"ตัวแปรนี้ไม่มีค่าอยู่";
}


ประมาณนี้ครับเกี่ยวกับ session ต้องการสอบถามอะไรเพิ่มเิติม เกี่ยวกับ session สอบถามเพิ่มเติมได้ในกระทู้นี้นะครับ

ย้อนกลับไปยัง

ผู้ใช้งานขณะนี้

กำลังดูบอร์ดนี้: 1 และ บุคคลทั่วไป 0 ท่าน

cron