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 6207353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:36:55+00:00 2026-05-24T05:36:55+00:00

i am making a POST request using curl and PHP, sending a username/password array

  • 0

i am making a POST request using curl and PHP, sending a username/password array as a JSON object.

so far all is working wonderfully. now i wanted to read the headers so i can parse the cookie. i know i can use a file/jar and have tested that – works well. i want to not write a thing to disk.

so i flagged CURLOPT_HEADER as TRUE and i can parse the cookie value.

HOWEVER – the returned data is gone. totally gone…
when i flag _HEADER FALSE – i see the response.

the code:

    $login_array = array('login' => array('username' => $username, 'password' => $password));
    $login_json = json_encode($login_array);

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, TRUE); <-- this line f***s it all up...
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $login_json);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); 
    curl_setopt($ch, CURLOPT_URL, 'http://localhost/test/token');

    $result = curl_exec($ch);

    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($http_code != 200) { /* do something */ }

    preg_match_all('|Set-Cookie: (.*);|U', $result, $content);    
    $cookies = implode(';', $content[1]);
    echo "cookie: $cookies<br>"; <-- thanks _HEADER for the cookie value

    $response = json_decode($result);
    $user_id = $response->user->id;
    echo 'user_id: ' . $user_id . '<br>'; <-- empty man... headers are on means body is off...

i’ve been digging through different posts and it seems the order of the opts makes a difference. tried moving them about – no luck.

thoughts?!

  • 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-05-24T05:36:55+00:00Added an answer on May 24, 2026 at 5:36 am

    Use:

    $body=mb_substr($result, curl_getinfo($ch,CURLINFO_HEADER_SIZE));
    $response = json_decode($body);
    $user_id = $response->user->id;
    echo 'user_id: ' . $user_id . '<br>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I am basically making a script to pass post data using cURL.
I am making a POST request from IE using XDomainRequest . XDomainRequest does not
I am making request calls using $.ajax, with post. The problem is, the post
I'm having troubles debugging a POST request I'm making from my web server to
I am making a POST to another php file that I want to render
How does one create a POST request using TCPSocket in Ruby? Is there a
I want to invoke an ASP.NET web service via an http POST request using
I am using struts2 and jquery I am making a server request using XMLHttpRequest
I'm making a simple POST request via jquery's .ajax function to a routed URL
I'm making paypal request using Ajax calling but I'm getting error with status ZERO.The

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.