SlideShare ist ein Scribd-Unternehmen logo
1 von 11
1
žคุกกี้ (Cookies)
ž คุกกี้ คือ Text file ขนาดเล็ก ที่มีขนาดในแต่ละชุดไม่
เกิน 4 kB โดยถูกจำาเก็บอยู่บนเครื่องคอมพิวเตอร์ด้านฝั่งของ
ไคลเอนต์หรือผู้ใช้โปรแกรม Browser
ž ภายในคุกกี้แต่ละตัวจะมีส่วนประกอบไปด้วย ชื่อ
คุกกี้ (Name) ค่าคุกกี้ (Value) และวันหมดอายุ (Expiry
Date) พร้อมกับข้อมูลเกี่ยวกับ Host และ Path
ž Cookies ถูกสร้างขึ้นเมื่อไร
ž โดยปกติ Cookies จะถูกกำาหนดมาพร้อมกับข้อมูล
ที่ Web Server ส่งมาให้กับ Client โดยจะอยู่ในส่วนของ
HTTP Header
ž เมื่อฝั่ง Client ได้รับ HTTP Header มา และตรวจ
สอบพบว่ามี Cookies ส่งมาด้วยหรือไม่ ถ้ามี Client จะนำา
ข้อมูลนั้นมาสร้างเป็นแฟ้มข้อมูล Cookies เก็บไว้ที่เครื่องของ
ฝั่ง Client เอง ข้อมูล Cookies ที่เก็บไว้ฝั่ง Client นี้ เรา
สามารถเขียนโปรแกรมเพื่อดึงค่าเหล่านี้มาใช้ประโยชน์ได้ ดัง
จะได้กล่าวต่อไป
ž การสร้างและลบ Cookies
ž การเข้าถึง Cookie
ž การเข้าถึง Cookie ทำาได้หลายวิธีในที่นี้จะ
กล่าวถึง 2 วิธี
อ้างถึงชื่อ Cookie โดยตรง เช่น
ž echo $TestCookie;
//TestCookie คือชื่อ Cookie
2
ž อ้างผ่าน $HTTP_COOKIE_VARS[]
ž echo
$HTTP_COOKIE_VARS[TestCookie]
ž // TestCookie คือชื่อ Cookie
รูปแบบของ Cookkie
ž
3
ตัวอย่าง : Cookie
4
การรันหน้า Form ของ Cookie
ตัวอย่าง : Cookie
ตัวอย่าง : Cookie
5
ตัวอย่าง : การรัน Cookie
ž เซสชั่น (Session)
6
ž เซสชั่น (Session) เป็นตัวแปรชนิดหนึ่งที่ถูกสร้างขึ้นและ
เก็บไว้ที่ Web Server โดยเซสชั่นนี้จะหมดอายุเมื่อเราทำาการ
ปิดบราวเซอร์ของ Client
ž ตัวลูกข่าย (Client) จะติดต่อกับ Session โดยอาศัย
Session ID ที่ Web Server ส่งมาให้
ž สร้างเซสชั่น (Session)
ž เริ่มสร้างเซสชั่นด้วยฟังก์ชัน
session_start()
เมื่อใช้คำาสั่ง session_start() แล้วตัว Client จะได้รับ
session id เราสามารถดู session id ได้ด้วยคำาสั่ง
session_id()
ลงทะเบียนเซสชั่น เพื่อสร้าง ตัวแปรเซสชั่น
สร้างตัวแปรเซสชั่น โดยใช้ฟังก์ชั่น session_register()
session_register (ชื่อตัวแปร[, ชื่อตัวแปร...])
$ชื่อตัวแปร = "ค่าที่กำาหนดให้ตัวแปร"
ตัวอย่าง
session_register("myname");
//ลงทะเบียนตัวแปร $myname
$myname = "สมชาย"
ž สร้างตัวแปรเซสชั่น โดยใช้ตัวแปรเซสชั่น
$HTTP_SESSION_VARS
7
$HTTP_SESSION_VARS['ชื่อตัวแปร'] = ค่าที่กำาหนด
ž ตัวอย่าง
$HTTP_SESSION_VARS['name']='sompot';
//สร้างตัวแปรเซสชั่น name
สร้างตัวแปรเซสชั่น โดยใช้ตัวแปรโดยใช้ตัวแปรเซสชั่น
$_SESSION
$_SESSION['ชื่อตัวแปรเซสชั่น']= ค่าที่จะก าหนด
ž ตัวอย่าง
$_SESSION['name']='sompot';
//สร้างตัวแปรเซสชั่น name
ž การยกเลิกตัวแปรเซสชั่น และการทำาลายเซสชั่นทั้ง
หมด
การยกเลิกตัวแปรเซสชั่นโดยเจาะจงเฉพาะตัวแปรเซสชั่น
บางตัว สามารถทำาได้โดยใช้คำาสั่ง
unset($_SESSION['ชื่อตัวแปรเซสชั่น'])
session_unregister(ชื่อตัวแปร);
ž เราสามารถทำาลายเซสชั่นทั้งหมดได้โดยใช้คำาสั่ง
ž session_unset();
session_destroy();
8
รูปแบบ Session
ตัวอย่าง : Session
9
ตัวอย่าง : การรัน Session
ตัวอย่าง : การเรียกค่าของ Session
10
ตัวอย่าง : การรัน Session
อ้างอิง
11
http://code.function.in.th/jsp/cookie
http://www.chiangkham.ac.th/krudui/index.php/se
ssion

Weitere ähnliche Inhalte

Empfohlen

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Empfohlen (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

รายงานพรีเซน Sessioncookie

  • 1. 1 žคุกกี้ (Cookies) ž คุกกี้ คือ Text file ขนาดเล็ก ที่มีขนาดในแต่ละชุดไม่ เกิน 4 kB โดยถูกจำาเก็บอยู่บนเครื่องคอมพิวเตอร์ด้านฝั่งของ ไคลเอนต์หรือผู้ใช้โปรแกรม Browser ž ภายในคุกกี้แต่ละตัวจะมีส่วนประกอบไปด้วย ชื่อ คุกกี้ (Name) ค่าคุกกี้ (Value) และวันหมดอายุ (Expiry Date) พร้อมกับข้อมูลเกี่ยวกับ Host และ Path ž Cookies ถูกสร้างขึ้นเมื่อไร ž โดยปกติ Cookies จะถูกกำาหนดมาพร้อมกับข้อมูล ที่ Web Server ส่งมาให้กับ Client โดยจะอยู่ในส่วนของ HTTP Header ž เมื่อฝั่ง Client ได้รับ HTTP Header มา และตรวจ สอบพบว่ามี Cookies ส่งมาด้วยหรือไม่ ถ้ามี Client จะนำา ข้อมูลนั้นมาสร้างเป็นแฟ้มข้อมูล Cookies เก็บไว้ที่เครื่องของ ฝั่ง Client เอง ข้อมูล Cookies ที่เก็บไว้ฝั่ง Client นี้ เรา สามารถเขียนโปรแกรมเพื่อดึงค่าเหล่านี้มาใช้ประโยชน์ได้ ดัง จะได้กล่าวต่อไป ž การสร้างและลบ Cookies ž การเข้าถึง Cookie ž การเข้าถึง Cookie ทำาได้หลายวิธีในที่นี้จะ กล่าวถึง 2 วิธี อ้างถึงชื่อ Cookie โดยตรง เช่น ž echo $TestCookie; //TestCookie คือชื่อ Cookie
  • 2. 2 ž อ้างผ่าน $HTTP_COOKIE_VARS[] ž echo $HTTP_COOKIE_VARS[TestCookie] ž // TestCookie คือชื่อ Cookie รูปแบบของ Cookkie ž
  • 4. 4 การรันหน้า Form ของ Cookie ตัวอย่าง : Cookie ตัวอย่าง : Cookie
  • 5. 5 ตัวอย่าง : การรัน Cookie ž เซสชั่น (Session)
  • 6. 6 ž เซสชั่น (Session) เป็นตัวแปรชนิดหนึ่งที่ถูกสร้างขึ้นและ เก็บไว้ที่ Web Server โดยเซสชั่นนี้จะหมดอายุเมื่อเราทำาการ ปิดบราวเซอร์ของ Client ž ตัวลูกข่าย (Client) จะติดต่อกับ Session โดยอาศัย Session ID ที่ Web Server ส่งมาให้ ž สร้างเซสชั่น (Session) ž เริ่มสร้างเซสชั่นด้วยฟังก์ชัน session_start() เมื่อใช้คำาสั่ง session_start() แล้วตัว Client จะได้รับ session id เราสามารถดู session id ได้ด้วยคำาสั่ง session_id() ลงทะเบียนเซสชั่น เพื่อสร้าง ตัวแปรเซสชั่น สร้างตัวแปรเซสชั่น โดยใช้ฟังก์ชั่น session_register() session_register (ชื่อตัวแปร[, ชื่อตัวแปร...]) $ชื่อตัวแปร = "ค่าที่กำาหนดให้ตัวแปร" ตัวอย่าง session_register("myname"); //ลงทะเบียนตัวแปร $myname $myname = "สมชาย" ž สร้างตัวแปรเซสชั่น โดยใช้ตัวแปรเซสชั่น $HTTP_SESSION_VARS
  • 7. 7 $HTTP_SESSION_VARS['ชื่อตัวแปร'] = ค่าที่กำาหนด ž ตัวอย่าง $HTTP_SESSION_VARS['name']='sompot'; //สร้างตัวแปรเซสชั่น name สร้างตัวแปรเซสชั่น โดยใช้ตัวแปรโดยใช้ตัวแปรเซสชั่น $_SESSION $_SESSION['ชื่อตัวแปรเซสชั่น']= ค่าที่จะก าหนด ž ตัวอย่าง $_SESSION['name']='sompot'; //สร้างตัวแปรเซสชั่น name ž การยกเลิกตัวแปรเซสชั่น และการทำาลายเซสชั่นทั้ง หมด การยกเลิกตัวแปรเซสชั่นโดยเจาะจงเฉพาะตัวแปรเซสชั่น บางตัว สามารถทำาได้โดยใช้คำาสั่ง unset($_SESSION['ชื่อตัวแปรเซสชั่น']) session_unregister(ชื่อตัวแปร); ž เราสามารถทำาลายเซสชั่นทั้งหมดได้โดยใช้คำาสั่ง ž session_unset(); session_destroy();
  • 9. 9 ตัวอย่าง : การรัน Session ตัวอย่าง : การเรียกค่าของ Session
  • 10. 10 ตัวอย่าง : การรัน Session อ้างอิง