100%
  • ดีมาก
  • ดี
  • ปานกลาง
  • แย่
  • แย่มาก
ให้คะแนนสำหรับบทความนี้

การใช้งาน HTTP Headers

ปรับปรุงข้อมูลล่าสุดเมื่อ 19 ธ.ค. 54 + 20:22

แจ้ง Browser ว่าเกิดอะไรขึ้น

บอกไปว่า ทุกอย่างปกติดี

header('HTTP/1.1 200 OK');

ไม่พบไฟล์ที่ต้องการเปิด

header('HTTP/1.1 404 Not Found');

ไม่อนุญาตให้เข้าใช้

header('HTTP/1.1 403 Forbidden');

ย้ายที่แล้ว (มักใช้คู่กับ Redirect)

header('HTTP/1.1 301 Moved Permanently');

ไม่มีการเปลี่ยนแปลง (จะได้ไปดึง cache)

header('HTTP/1.1 304 Not Modified');

เซิฟเวอร์เน่า

header('HTTP/1.1 500 Internal Server Error');

Redirect

header('Location: http://www.example.org/');

แบบนับเวลาถอยหลัง

header('Refresh: 10; url=http://www.example.org/');

เนื้อหาข้อมูล

บอกว่าทำงานด้วยอะไร

header('X-Powered-By: PHP/6.0.0');
header('X-Powered-By: un-no/2.2.0');

ระบุภาษาที่ใช้ (th คือ ภาษาไทย)

header('Content-language: th');

แก้ไขล่าสุด (ไว้สำหรับการ cache)

$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');

ขนาดข้อมูล (ไว้สำหรับการ cache)

header('Content-Length: 1234');

สำหรับใช้ดาวน์โหลดไฟล์

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"'); 
header('Content-Transfer-Encoding: binary');

// load the file to send:
readfile('example.zip');

ปิดการ Cache

header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');

กำหนดชนิดของไฟล์

header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain'); // plain text file
header('Content-Type: image/jpeg'); // JPG picture
header('Content-Type: application/zip'); // ZIP file
header('Content-Type: application/pdf'); // PDF file
header('Content-Type: audio/mpeg'); // Audio MPEG (MP3,...) file
header('Content-Type: application/x-shockwave-flash'); // Flash animation

แสดง หน้าต่าง Login

header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Login"');

ไม่สามารถแสดงความคิดเห็นได้ จำเป็นต้อง เข้าระบบสมาชิก ก่อน หรือ สมัครสมาชิกใหม่

ขับเคลื่อนโดย un-no Engine 2.2.0 © โดย บริษัท อันโน คอร์ปอเรชั่น จำกัด [ แผนที่เว็บไซต์ ]

แก้ไขล่าสุด: 2011-12-19 19:45:38, หมายเลขเซสชั่น: eq3vobm4umdlm1iclrotg4pdp4, ใช้เวลาสร้าง: 0.017235041 วินาที (force)