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

  • Home
  • SEARCH
  • 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 8966371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:00:50+00:00 2026-06-15T17:00:50+00:00

I’m having a little difficulty in figuring out how to run multiple cURL requests,

  • 0

I’m having a little difficulty in figuring out how to run multiple cURL requests, and I’m not entirely sure what I’m doing wrong. It may be that my code for logging in via the webform that I’ve written is incorrect, but its difficult to test that on its own as I do need to run the first query before I can do that.

This is the code I have for my first query;

$handle = curl_init();

$login_user = 'user';
$login_pass = 'pass';

$username = 'username';
$password = 'password';

$postdata = "username=".$username."&password=".$password; 

curl_setopt($handle, CURLOPT_URL, 'http://somewebsiteexample.php');
curl_setopt($handle, CURLOPT_USERPWD, $login_user . ":" . $login_pass );
curl_setopt($handle, CURLOPT_POST, true);

curl_setopt($handle, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($handle);
curl_close($handle);

echo '<pre>';
print_r($response);
?>

Which gets me past the basic http authentication. Now I need to be able to log in to the site by posting the request to the webform php page.

I’ve seen plenty of examples of how to do this, but only on their own, and not as a second cURL request.

I have all the information I need to be able to do each individual request, but I’m not sure how to combine the two requests together. Do I do it in the same cURL session?

I get the feeling that I do need to do seperate curl initialisation requests and that I need to store the login information from the first request via a cookie using CURLOPT_COOKIEJAR. (Or can I run my second query in the same curl_init()?)

If that is the case, how do I store the basic http authentication request so that when I next initialise curl, I am already logged into the website where I can then POST to the webform? I can probably figure out the rest once I know how to do multiple cURL requests.

I’m fairly new to cURL (I still use file_get_contents() for web pages a lot of the time), so I’m also a little unsure on which cURL options are absolutely necessary for logging in via webform. Some seem quite obvious, whereas others do not. This is something I can probably figure out on my own, but its hard to find a solid tutorial for logging in with cURL that has a breakdown of what each CURLOPT constant does in that particular context.

The php.net manual has a lot of information, and while it does tell you what the various cURL options relate to, it doesn’t provide specific examples of their specific usages. If there is another resource site where I can get a more in-depth explanation of cURL, that would also be appreciated.

  • 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-15T17:00:52+00:00Added an answer on June 15, 2026 at 5:00 pm

    You need to look into ways curl is debugged. Curl naturally won’t trace anything, you need to call for curl_error($curl) and curl_errno($curl) after the request, but before the resource is closed with curl_close($curl).

    You also need to trace curl_getinfo($curl) for details regarding request and response. Make sure your blank page is not caused by syntax errors in your script.

    Next part. Add CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE for cookies handling. Do the second request on the same curl resource, run curl_close($curl) after all requests have been done. Curl saved most of the setup between requests, so don’t worry about that.

    I would also suggest adding user agent and referer settings to make your request look more natural.

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

Sidebar

Related Questions

I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.