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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:19:53+00:00 2026-06-14T17:19:53+00:00

I’m having issues with following a redirect while maintaining session cookie and post field

  • 0

I’m having issues with following a redirect while maintaining session cookie and post field information. This is how the process goes:

1) Visit URL, they return a cookie and a 302 response (pointing to the same URL you just visited)

2) Re-Visit URL with the cookie they gave you and you can see the proper page.

I can get through to the proper page with CURLOPT_FOLLOWLOCATION = true, however I guess CURL doesn’t keep the post fields when following a redirect, so there is no useful content on the page.

I have tried manually storing the cookie, and performing the ‘redirect’ myself with the stored cookie, however with this method I never get past the 302 redirect to the proper page. The code for the manual method mentioned here is below.

$tmp_name = tempnam('tmp', 'COOKIE');
$url = "MY_URL";

$options = array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_REFERER => $url,
    CURLOPT_HEADER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => array(
        'field1' => 'postfield1',
        'field2' => 'postfield2',
    ),
    CURLOPT_VERBOSE => true,
);

// Make the first request, specifying where to store the cookie
// This request returns the cookie and the 302 response
$ch = curl_init($url);
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmp_name);
$resp1 = curl_exec($ch);

// Make the second request, using the cookie stored above
// Should return the proper page, but gives me the 302 again instead.
$ch = curl_init($url);
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_COOKIEFILE, $tmp_name);
$resp2 = curl_exec($ch);

Does anyone know what’s wrong with the above code, or if there’s another way to accomplish the task?

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

    First of all, post data is never kept on redirect. So don’t worry about that, you don’t have to make two requests. Just stick with

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    

    I would also suggest the following for further debuging: even if you make two requests, use same curl resource, don’t close it to make new one. Also, add:

    curl_setopt($ch, CURLOPT_FORBID_REUSE, 0);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, 0);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "valid user agent");
    

    You could also use browser addons (i.e. HttpFox) to check the exact cookies and requests sequence that are needed. You are trying to emulate real request, so looking in-depth at one that your browser makes can help a lot.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Let's say I'm outputting a post title and in our database, it's Hello Y’all
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.