Home > 类库下载 > PHP类库 > body text

PHP sends request headers and receives print request headers

高洛峰
Release: 2016-10-10 10:25:31
Original
2053 people have browsed it

PHP sends request headers and receives print request headers

1. Send request headers

//发送地址
$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;
Copy after login

2. Receive and print request headers

$headers = array();
foreach ($_SERVER as $key => $value) {
    if ('HTTP_' == substr($key, 0, 5)) {
        $headers[str_replace('_', '-', substr($key, 5))] = $value;
    }
}    
echo &#39;<pre class="brush:php;toolbar:false">&#39;;
print_r($headers);
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!