一、發送請求頭
//發送地址 $url = 'http://127.0.0.1/2.php'; //請求頭內容 $headers = array( 'Authorization: '.$basic, 'suibianzhi: '.$basic, ); //使用curl發送 $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); curl_close($ch); echo $result;
二、接收並打印請求頭
$headers = array(); foreach ($_SERVER as $key => $value) { if ('HTTP_' == substr($key, 0, 5)) { $headers[str_replace('_', '-', substr($key, 5))] = $value; } } echo '<pre>'; print_r($headers);