: This article describes how to send custom data through the header in php. For more information about PHP tutorials, see. This article describes how to send custom data through the header. When sending a request, you can use $ _ GET/$ _ POST to send data, or put the data in the header for transmission.
Sending header:
We have defined three parameters, token, language, and region, and put them in the header to send them.
'Fdipregion'); $ response = tocurl ($ url, $ header, $ content); $ data = json_decode ($ response, true); echo 'post data: '; echo'';print_r($data['post']);echo'
'; Echo 'header data:'; echo'';print_r($data['header']);echo'
'; /*** Send data ** @ param String $ url request address * @ param Array $ header custom header data * @ param Array $ content POST data * @ return String * /functiontocurl ($ url, $ header, $ content) {$ ch = curl_init (); if (substr ($ url, 0,5) = 'https') {curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false ); // skip the certificate check curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, true); // check whether the SSL encryption algorithm exists from the certificate} curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true); curl_s Etopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header); curl_setopt ($ ch, CURLOPT_POST, true); curl_setopt ($ ch, CURLOPT_POSTFIELDS, http_build_query ($ content); $ response = curl_exec ($ ch); if ($ error = curl_error ($ ch) {die ($ error );} curl_close ($ ch); return $ response;}?>
Receive header
We can get the header data in $ _ SERVER. Custom Data uses HTTP _ as the prefix, so we can read the HTTP _ prefix data.
$ Value) {if (substr ($ key, 0, 5) === 'http _ ') {$ key = substr ($ key, 5 ); $ key = str_replace ('_', '', $ key); $ key = str_replace ('', '-', $ key ); $ key = strtolower ($ key); if (! In_array ($ key, $ ignore) {$ headers [$ key] = $ value ;}} return $ headers ;}?>
Output:
POST data:Array( [name] => fdipzone)Header data:Array( [token] => JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU [language] => zh [region] => GZ)
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above describes how php sends custom data through the header, including some content, and hope to be helpful to friends who are interested in the PHP Tutorial.