Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฉันจะให้ PHP แสดงส่วนหัวที่ได้รับจากเบราว์เซอร์ได้อย่างไร


บรรทัดด้านล่างของรหัสสามารถใช้เพื่อแสดงส่วนหัวที่รหัส PHP ได้รับผ่านเบราว์เซอร์ -

<?php print_r($_SERVER[URL]) ?>

หรือ

ตัวอย่าง

$headers = getallheaders();
foreach($headers as $key=>$val){
   echo $key . ': ' . $val . '<br>';
}

ผลลัพธ์

สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

Host: www.websitename.com
Content-Length: 180
Cache-Control: max-age=0
Origin: https://www.websitename.com
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: https://www.writephponline.com/
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
Cookie: _ga=GA1.2.118418268.1575911248; _gid=GA1.2.1794052867.1576852059