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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:12:32+00:00 2026-05-23T05:12:32+00:00

Im using cURL to post data to a php file (setcookie.php) on another domain.

  • 0

Im using cURL to post data to a php file (setcookie.php) on another domain.

The file, setcookie.php is supposed to set a cookie on that domain with the data posted to it.

The problem is the cookie doesn’t want to be set when im doing it with cURL, because cURL returns to the calling file/domain, i guess.

So how can I make cURL not come back to the calling file?

Or is there an easier way to do this?

Here’s my code :

$ch = curl_init ("http://<other domain>/setnewcookie.php");
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, false);
$returndata = curl_exec ($ch);
  • 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-23T05:12:32+00:00Added an answer on May 23, 2026 at 5:12 am

    Here’s what you need to do:

    $ch = curl_init('http://example.org/setnewcookie.php');
    
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    
    curl_exec($ch);
    

    For cookies to work with cURL, you need to define both CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE. ALso, if you don’t want the content of “http://example.org/setnewcookie.php” to be outputted to the browser, you need to set CURLOPT_RETURNTRANSFER to TRUE.

    This will create a cookie on your server that cURL can use for subsequent requests but it won’t allow the user of your website for instance to use that cookie. If the intent is for the user to be logged in on both sites, this will not work as-is.

    For cross sub-domains (as in between www1.example.org and www2.example.org), have a look at PHP authentication with multiple domains and subdomains.

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

Sidebar

Related Questions

passing post data using cURL requires that the name of the input. However, I
I need to POST some data to a PHP page using cURL, and the
I have a python script that is using curl to post a file into
I have a PHP file that invokes another PHP file via curl. I am
I'm posting a request with POST data using cURL to a PHP script here:
I am using PHP curl functions to post data to the web server from
Okay, so I am basically making a script to pass post data using cURL.
I want to POST an URL using CURL and php. There is a big
How can I do a RAW POST in PHP using cURL? Raw post as
I am attempting to POST against a vendor's server using PHP 5.2 with cURL.

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.