Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8794099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:12:25+00:00 2026-06-13T23:12:25+00:00

trying to do the equivalent of this in PHP – and failing :): curl

  • 0

trying to do the equivalent of this in PHP – and failing :):

curl -H "X-abc-AUTH: 123456789" http://APIserviceProvider=http://www.cnn.com;

“123456789” is the API key. The command line statement works fine.

PHP code (does not work):

$urlToGet = "http://www.cnn.com";
$service_url = "http://APIserviceProvider=$urlToGet";

//header

 $contentType = 'text/xml';          //probably not needed
 $method = 'POST';                   //probably not needed
 $auth = 'X-abc-AUTH: 123456789';    //API Key

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $service_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

//does not work



// curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-type: ' . 
   // $contentType . '; auth=' . $auth));

    //works!   (THANKS @Fratyr for the clue):

    curl_setopt($ch, CURLOPT_HTTPHEADER, Array($auth));

//this works too (THANKS @sergiocruz):

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  'Some_custom_header: 0',
  'Another_custom_header: 143444,12'
));


//exec

$data = curl_exec($ch);
echo $data;
curl_close($ch);

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:12:26+00:00Added an answer on June 13, 2026 at 11:12 pm

    In order to get custom headers into your curl you should do something like the following:

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Some_custom_header: 0',
      'Another_custom_header: 143444,12'
    ));
    

    Therefore the following should work in your case (given X-abc-AUTH is the only header you need to send over):

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'X-abc-AUTH: 123456789' // you can replace this with your $auth variable
    ));
    

    If you need additional custom headers, all you have to do is add on to the array within the curl_setopt.

    I hope this helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get an HttpRequest to post this URL https://www.iformbuilder.com/exzact/_emptyTable.php?PAGE_ID=1234&TABLE_NAME=table_name_here&USERNAME=yo@yo.com&PASSWORD=What!What ! I've tried
I have PHP source code of http://www.sitename.com . This site is located on Windows
I'm trying to translate the following slugify method from PHP to C#: http://snipplr.com/view/22741/slugify-a-string-in-php/ Edit:
I'm trying to find the jQuery equivalent of this JavaScript method call: document.addEventListener('click', select_element,
I am trying to construct equivalent of this code in JSF2 <form action=/search.xhtml method=get>
I am trying to achieve the equivalent of this in mongoid (mongoid.org ORM): select
I'm trying to figure out the F# equivalent of this C# Attribute delclaration: [
Ok, Im trying to convert a javascript timestamp to a php equivalent, I have
I'm trying to create a redirect from http://example.com/links/AAA to http://links.example.net/l/AAA (where AAA is a
I have a PHP/MySQL website on 000webhost (http://www.boisvert.me.uk; but it's down for review at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.