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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:43:47+00:00 2026-05-27T16:43:47+00:00

Edit: Why the minus one? What I am trying to do is the following:

  • 0

Edit: Why the minus one?

What I am trying to do is the following:

  • I am trying to login to my school site using cURL and grab the schedule to use it for my AI.

So I need to login using my pass and number, but the form on the school site also needs a hidden ‘token’.

<form action="index.php" method="post">
    <input type="hidden" name="token" value="becb14a25acf2a0e697b50eae3f0f205" />
    <input type="text" name="user" />
    <input type="password" name="password" />
    <input type="submit" value="submit">
</form>

I’m able to successfully retrieve the token. Then I try to login, but it fails.

// Getting the whole website
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.school.com');
$data = curl_exec($ch);

// Retrieving the token and putting it in a POST
$regex = '/<regexThatWorks>/';
preg_match($regex,$data,$match);
$postfields = "user=<number>&password=<secret>&token=$match[1]";

// Should I use a fresh cURL here?

// Setting the POST options, etc.
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);

// I won't use CURLOPT_RETURNTRANSFER yet, first I want to see results. 
$data = curl_exec($ch);

curl_close($ch); 

Well… It doesn’t work…

  • Is it possible the token changes every curl_exec? Because the site doesn’t recognize the script the second time…
  • Should I create a new cURL instance(?) for the second part?
  • Is there another way to grab the token within 1 connection?
  • Cookies?
  • 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-27T16:43:48+00:00Added an answer on May 27, 2026 at 4:43 pm

    This is how I solved it. The problem was probably the ‘not-using-cookies’ part.
    Still this is probably ‘ugly’ code, so any improvements are welcome!

    // This part is for retrieving the token from the hidden field.
    // To be honest, I have no idea what the cookie lines actually do, but it works.
    $getToken= curl_init();
    curl_setopt($getToken, CURLOPT_URL, '<schoolsite>');       // Set the link
    curl_setopt($getToken, CURLOPT_COOKIEJAR, 'cookies.txt');  // Magic
    curl_setopt($getToken, CURLOPT_COOKIEFILE, 'cookies.txt'); // Magic
    curl_setopt($getToken, CURLOPT_RETURNTRANSFER, 1);         // Return only as a string
    $data = curl_exec($token);                                 // Perform action
    
    // Close the connection if there are no errors
    if(curl_errno($token)){print curl_error($token);}
    else{curl_close($token);} 
    
    // Use a regular expression to fetch the token
    $regex = '/name="token" value="(.*?)"/';
    preg_match($regex,$data,$match);
    
    // Put the login info and the token in a post header string
    $postfield = "token=$match[1]&user=<number>&paswoord=<mine>";
    echo($postfields);
    
    // This part is for logging in and getting the data.
    $site = curl_init();
    curl_setopt($site, CURLOPT_URL, '<school site');
    curl_setopt($site, CURLOPT_COOKIEJAR, 'cookies.txt');    // Magic
    curl_setopt($site, CURLOPT_COOKIEFILE, 'cookies.txt');   // Magic
    curl_setopt($site, CURLOPT_POST, 1);                     // Use POST (not GET)
    curl_setopt($site, CURLOPT_POSTFIELDS, $postfield);      // Insert headers
    $forevil_uuh_no_GOOD_purposes = curl_exec($site);        // Output the results
    
    // Close connection if no errors           
    if(curl_errno($site)){print curl_error($site);}
    else{curl_close($site);} 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: OK, I believe the following solutions are valid: Use the jQuery AOP plugin.
What is the best method of using native menus in C#? Edit: I want
EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been
EDIT: I used, finally, inotify. As stefanB says, inotify is the thing to use.
I'm trying to use PHP to create a file, but it isn't working. I
I am trying to use the code in this article that lets you know
I'm trying to order the values in a related table using LINQ to SQL
I am using acts_as_list on my Product model, and trying to make it so
I'm using OpenGL to draw in 2D. I'm trying to overlay textures with alpha.
How can I use OpenGLES 1.1 (iPhone) to draw a texture, but only using

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.