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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:28:44+00:00 2026-06-16T13:28:44+00:00

Basically, I have a script that logs in to a website, and downloads a

  • 0

Basically, I have a script that logs in to a website, and downloads a file. Fairly straight forward. Unfortunately something’s missing in my code that’s preventing it from working properly.

When I run it, I get back a html page outputted to my file which is exactly what I would get in my browser if I was attempting to access the file link without being logged on; access denied, you must be logged in, etc.

However, if I run the first part of my script on its own by commenting out the file download request, then re-run the script in its entirety, I am able to download the file as I should, so I know it’s working in a sense. It just doesn’t seem to want to log me in when I run the entire script.

// Log me in

curl_setopt($handle, CURLOPT_URL, $login_url); 
curl_setopt($handle, CURLOPT_REFERER, $admin_url);
curl_setopt($handle, CURLOPT_COOKIEJAR, $Cookie_Location);
curl_setopt($handle, CURLOPT_COOKIEFILE, $cookie); 
curl_setopt($handle, CURLOPT_TIMEOUT, 60); 
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); 

// Grab the file

curl_setopt($handle, CURLOPT_URL, $csv_loc);
curl_setopt($handle, CURLOPT_FILE, $csv_handle); 

echo $response = curl_exec($handle);

curl_close($handle);

So I can log in, then re-run the script and download the file, but I can’t do both at the same time. I’ve tried all sorts of different additional curl options such as COOKIEJAR and COOKIEFILE, as well as FOLLOWLOCATION and REFERER, which were my only hunches as to why my code wasn’t working. Something in my “Grab the file” code is either breaking my log in, or is behaving like I’m not logged in.

Edit: SOLVED.

I’ve decided to include the solution so others avoid the same mistake I did.

All I needed to do was seperate my requests, like so;

// Log me in

curl_setopt($handle, CURLOPT_URL, $login_url); 
curl_setopt($handle, CURLOPT_REFERER, $admin_url);
curl_setopt($handle, CURLOPT_COOKIEJAR, $Cookie_Location);
curl_setopt($handle, CURLOPT_COOKIEFILE, $cookie); 
curl_setopt($handle, CURLOPT_TIMEOUT, 60); 
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); 

echo $response = curl_exec($handle);

// Grab the file

curl_setopt($handle, CURLOPT_URL, $csv_loc);
curl_setopt($handle, CURLOPT_FILE, $csv_handle);

curl_exec($handle);

curl_close($handle);

First curl_exec logs me in to the site, and the second one then grabs and downloads my file. Then I just close the handle.

  • 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-16T13:28:45+00:00Added an answer on June 16, 2026 at 1:28 pm

    If this is exactly the code you are using, then:

    // Log me in
    curl_setopt($handle, CURLOPT_URL, $login_url); 
    
    // Grab the file
    curl_setopt($handle, CURLOPT_URL, $csv_loc);
    
    echo $response = curl_exec($handle);
    curl_close($handle);
    

    You are redefining your URL. You can not send a POST to one URL (login) and a GET (grab a file) in one request, you will need to send 2 separate requests for that.

    Unless your login form gives you file back as a response immediately.

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

Sidebar

Related Questions

Basically I have a script.js in my website that does this: if (someVar){ document.write('<script
I have a Python script that downloads a GRIB file (weather forecast data) from
So basically I have a PHP script that takes all the images from the
I have a script that I'm trying to get working. Basically, what I'm trying
Basically, I have a script that cannot see an existing directory on the OS
I am stuck with a peculiar issue here. I have a script that basically
I have a simple script that does some search and replace. This is basically
I have (basically) this code - <script type=text/javascript language=javascript> $(document).ready(function() { $(#loadDiv).load(mypage.html, function(){ alert($(#someText).text())
I have a sh/bash script that needs to call a batch file with parameters
Basically I have a script that updates an xml document in various places... However,

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.