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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:23:56+00:00 2026-06-11T23:23:56+00:00

Solved: Yay. In addition to what you wrote Drew, I found this: http://www.smooka.com/blog/2009/07/24/maintaining-php-session-when-using-curl/ session_write_close();

  • 0

Solved:
Yay. In addition to what you wrote Drew, I found this: http://www.smooka.com/blog/2009/07/24/maintaining-php-session-when-using-curl/
session_write_close(); before initializing the next set. Now I just need to figure out AJAX/jquery, because it looks like I can’t register resource variables (e.g. Curl’s handle) in a session.


I want to login to a site using cURL. Their login process uses a token which I am able to parse using file_get_contents(). However, when I try to access the site again using cURL, the token is no longer good. Is there a way read the file using cURL, pause to do the calculations/steps, and then post the fields? Is there a better way?

  • 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-11T23:23:57+00:00Added an answer on June 11, 2026 at 11:23 pm

    The token is probably no longer good because it is associated with a session cookie that gets set when you access the site. Since file_get_contents has no cookie tracking, you should use cURL to request the initial URL, grab the token, do your calculations, and then post back using cURL again.

    To get cURL to keep track of the cookies, use the CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR options for the cURL handle.

    $cookies = '/tmp/cookies.txt';  // path to cookie file
    $ch = curl_init('http://site.com');
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
    //...
    $res = curl_exec($ch);
    
    // grab token here...
    
    // do calculations here...
    
    curl_setopt($ch, CURLOPT_URL, 'http://site.com/next-url');
    
    $res = curl_exec($ch); // execute next request on same handle
    

    Here are some other answers of mine that use cURL to login to various websites and perform actions; looking at the code may be of help to you.

    • Login to Google with PHP and Curl, Cookie turned off?
    • PHP Curl – Cookies problem
    • Trouble getting a list of cities from LS
    • How to login in with Curl and SSL and cookies
    • How to make Curl post Using Php involving cookies
    • Retrieve Android Market mylibrary with curl
    • php cURL log into jsp website and return HTML
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

@Solved The two subquestions I have created have been solved (yay for splitting this
I searched, and found this question, which helped me: php static variable is not
SOLVED: Error in template file I have Smarty setup like this: require_once 'smarty/Smarty.class.php'; $smarty
SOLVED! Used this example from php.net post method handling multiple uploads, with the knowledge
Solved With the amount of information I provided this was unsolvable. A PHP library
Solved I actually found out what is going on here. Turns out it was
SOLVED: This is what was wrong: current.addFolder(folder); (in the final else clause of the
- Solved - I Know they exist, but I haven't found a slider that
(SOLVED, SEE END) I need hints on the PHP or MySQL code structure for
SOLVED http://jsfiddle.net/ArtofLife/u9d9d/ I have multiple TEXTAREA and BUTTON out side.. For inserting string in

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.