การใช้งาน header ใน PHP
การใช้ฟังก์ชั่น header ในภาษา php เราได้รวบรวมตัวอย่างการใช้งานไว้ดังนี้
redirect หน้าเว็บไปยัง URL อื่น ๆ
<?php
// Redirect to a new location:
header('Location: http://www.example.org/');
?>
redirect หน้าเว็บโดยให้แสดงแบบ refresh
<?php
// Redriect with a delay:
header('Refresh: 10; url=http://www.example.org/');
?>
กำหนดภาษาที่ใช้ในหน้าเว็บ
<?php
// content language (en = English)
header('Content-language: en');
?>
header สำหรับการสร้าง file download
<?php
// Headers for an download:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
// load the file to send:</p>
?>
สร้าง webpage โดยไม่ให้มีการเขียน chche
<?php
// Disable caching of the current document:
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
?>
กำหนดประเภท ของ content เว็บ
<?php
// set content type:
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 ให้ตรงกับ งานที่คุณต้องการใช้นะครับ


Aphorism
Фраза в тему:
Сегодня у меня хватило мужества отказать собственной сестре в сексе, но не хватило сноровки порно изнасилования меня ею.