Forum Moderators: coopster

Message Too Old, No Replies

Problem with cURL following URL

         

Crump

8:36 am on Dec 17, 2008 (gmt 0)

10+ Year Member



I have a script set up that I need to log in to a site. All is well and good, and the site goes to redirect. Lets say that the final result I want to see is this:

www.remotesite.com/anydir

However, the final result of the cURL is:

www.mysite.com/anydir

resulting in a 404 error code since I don't have /anydir on my server (it is on the remote server). I have battled with the cURL settings for the past couple days and nothing seems to work. Here is what I have right now:

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_MAXREDIRS, 0);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookiejar');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookiejar');
curl_setopt($ch, CURLOPT_COOKIE, "cookiejar");

This is frustrating! any help would be appreciated

milocold

8:48 am on Dec 17, 2008 (gmt 0)

10+ Year Member



Have you echo'd $url, is it an absolute address to the remote site?

-M. Cold

Crump

4:06 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



It is a full URL, as in:

http://www.example.com/login.php

[edited by: eelixduppy at 6:55 pm (utc) on Dec. 17, 2008]
[edit reason] exemplified [/edit]

Crump

11:46 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



No one?

leadegroot

6:19 am on Dec 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you saying there is a redirect that curl is not following?
If the server is setup such that the open_basedir is set, then curl will not follow a redirect.
Its good security, but damned annoying at times.

My solution when I have found this situation is to get the header result from curl and manually redo the curl.

Crump

6:34 pm on Dec 18, 2008 (gmt 0)

10+ Year Member



open_basedir is not set

How do I get the headers off curl? I have tried to do that with no luck

leadegroot

9:34 pm on Dec 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you need to read more thoroughly through the doc
[php.net...]
Theres a lot of stuff in there, but you have to have a strong handle on what you are doing, or you won't be successful.

If you turn on CURLOPT_HEADER you will get the headers returned. So:

curl_setopt($ch, CURLOPT_HEADER, true);