Php sends custom data through header

Source: Internet
Author: User
: 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.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.