cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Need guidance using cURL and Apache authentication

From: Charles <cecrume_at_gmail.com>
Date: Wed, 19 May 2010 00:33:22 -0400

Hello;

I'm have posted msgs to the curl-library mailing list, but am new to this list. I posted the message below and got some great help from Ralph Mitchell, but we were unable to actually get the URL transfer done. He suggested I post the msg here.

So...

I have a little membership system that I wrote in PHP and run on an Apache v2.0 web server. A couple of pages are protected with .htaccess files.

When a user logins into my membership system I don't want them to have to enter the username/password that Apache normally requires to gain access.

I have made some progress using cURL and can get the protected page to appear -- but cURL does not transfer to the actual URL specified. The browser shows the page, and it's contents, but the links (the page contains files to download) are bad because they are relative links.

1) Login to membership system.
2) Click on link "Download Updates" link on main page and it runs http://www.charlescrumesoftware.com/members/user_downloads.php
3) The above PHP script runs the following cURL code (among other stuff):

      $Cookie_Jar = "Cookie_Jar.doc";
      $c = curl_init("http://www.charlescrumesoftware.com/downloads/dms"); // the actual page I want
      curl_setopt($c, CURLOPT_COOKIE, 1);
      curl_setopt($c, CURLOPT_COOKIEJAR, "$Cookie_Jar");
      curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); // -L
      curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
      curl_setopt($c, CURLOPT_USERPWD, "UserName:Password");
   // curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); // save cURL output to file
      curl_setopt($c, CURLOPT_RETURNTRANSFER, 0); // allows us to FOLLOW
      $myDOWN_Page = curl_exec($c);
      curl_close($c);

4) the browser show the contents of the "download" page correctly -- but IE shows http://www.charlescrumesoftware.com/members/user_downloads.php in the address bar.

5) If I click on the "Parent Directory" link I am taken up one level in the directory structure -- as I should.

6) However... All the links to files that can be downloaded are relative links:

       <a href="DMSv64Update.zip">

   so I get taken to a page that does not exist.

   http://www.charlescrumesoftware.com/members/DMSv64Update.zip

I thought about POSTing the username and password, but am not sure what the variable names are that Apache recognizes.

I also realize I could save the page's contents, use PHP to alter all the links, then display the result -- but would prefer to just access the page directly, if possible.

Can someone shed some light on what I am overlooking here? Perhaps I am not understanding how CURLOPT_FOLLOWLOCATION works.

TIA.

Charles...
-----------------------
The more adapted you become... the less adaptable you are!!
Thanks.

Charles...
-----------------------
MIST (Man In The Street) Law: The number of people watching you is directly proportional to the stupidity of your action.

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2010-05-19