PHP sends request headers and receives print request headers
1. Send request header
<span style="color: #008000;">//</span><span style="color: #008000;">发送地址</span> <span style="color: #800080;">$url</span> = 'http://127.0.0.1/2.php'<span style="color: #000000;">; </span><span style="color: #008000;">//</span><span style="color: #008000;">请求头内容</span> <span style="color: #800080;">$headers</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">( </span>'Authorization: '.<span style="color: #800080;">$basic</span>, 'suibianzhi: '.<span style="color: #800080;">$basic</span>,<span style="color: #000000;"> ); </span><span style="color: #008000;">//</span><span style="color: #008000;">使用curl发送</span> <span style="color: #800080;">$ch</span> = curl_init(<span style="color: #800080;">$url</span><span style="color: #000000;">); curl_setopt(</span><span style="color: #800080;">$ch</span>, CURLOPT_RETURNTRANSFER, <span style="color: #0000ff;">true</span><span style="color: #000000;">); curl_setopt(</span><span style="color: #800080;">$ch</span>, CURLOPT_SSL_VERIFYPEER, <span style="color: #0000ff;">false</span><span style="color: #000000;">); curl_setopt(</span><span style="color: #800080;">$ch</span>, CURLOPT_SSL_VERIFYHOST, <span style="color: #0000ff;">false</span><span style="color: #000000;">); curl_setopt(</span><span style="color: #800080;">$ch</span>, CURLOPT_HTTPHEADER, <span style="color: #800080;">$headers</span><span style="color: #000000;">); </span><span style="color: #800080;">$result</span> = curl_exec(<span style="color: #800080;">$ch</span><span style="color: #000000;">); curl_close(</span><span style="color: #800080;">$ch</span><span style="color: #000000;">); </span><span style="color: #0000ff;">echo</span> <span style="color: #800080;">$result</span>;
Copy after login
2. Receive and print the request header
<span style="color: #800080;">$headers</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">(); </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$_SERVER</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$key</span> => <span style="color: #800080;">$value</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">if</span> ('HTTP_' == <span style="color: #008080;">substr</span>(<span style="color: #800080;">$key</span>, 0, 5<span style="color: #000000;">)) { </span><span style="color: #800080;">$headers</span>[<span style="color: #008080;">str_replace</span>('_', '-', <span style="color: #008080;">substr</span>(<span style="color: #800080;">$key</span>, 5))] = <span style="color: #800080;">$value</span><span style="color: #000000;">; } } </span><span style="color: #0000ff;">echo</span> '<pre class="brush:php;toolbar:false">'<span style="color: #000000;">; </span><span style="color: #008080;">print_r</span>(<span style="color: #800080;">$headers</span>);
Copy after login
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
What's New in Windows 11 KB5054979 & How to Fix Update Issues
3 weeks ago
By DDD
How to fix KB5055523 fails to install in Windows 11?
2 weeks ago
By DDD
InZoi: How To Apply To School And University
3 weeks ago
By DDD
How to fix KB5055518 fails to install in Windows 10?
2 weeks ago
By DDD
Roblox: Dead Rails – How To Summon And Defeat Nikola Tesla
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
