Re: advanced cURL problem ?
| From: | Scott Fletcher | Date: | Tue, 22 Apr 2003 15:27:10 +0000 |
| Subject: | Re: advanced cURL problem ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144838@lists.php.net to get a copy of this message | ||
The problem usually is the way we use the cURL command. cURL does most of
the work automatically, so all we need to do is to an one line command and
include the prefix options. Something like this with -m, -d, etc....
--clip--
define(CURL_CMD,"/usr/local/bin/curl");
exec(CURL_CMD." -m 120 -u \"$XP_BASIC_AUTH\" -d \"$XML_REQ_STR\"
".$SECOND_URL, $xp_result_array, $res_code);
--clip--
Since you mention about using the cookie, you may would not want to do this
because IE, Mozilla and other browser have the feature that block the use of
hte cookie. So, you're better off with the Session that create and use
files on the server instead of having the cookie on the client's machine...
"Joel Colombo" <joel@playoutloud.net> wrote in message
news:20030422134200.43443.qmail@pb1.pair.com...
> I am curling a site that sets a session cookie.
> When i enable cookie prompting in IE 6 it shows me the session cookie and
> asks if i want it set.
> but when i curl to the exact same URL it does not show up in the headers.
> i also think i am using the cookie options correctly...
>
> THIS CALL JUST HITS THE SITE TO SET A SESSION.
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL, $original_URL_that starts_my session);
> curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
> curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
> curl_setopt($ch, CURLOPT_HEADER, 1);
> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
> $curl_result = curl_exec($ch);
>
> << I parse the result looking for header cookie or whatever for session id
> set it to $SID >>
>
> THIS PIECE CALLS THE AREA REQUIRING THE SESSION TO BE SET (as you see i
> attempt $SID)
> $ch2 = curl_init();
> curl_setopt($ch2, CURLOPT_URL, $new_URL_that_requires_session);
> curl_setopt($ch2, CURLOPT_POST, 1);
> curl_setopt($ch2, CURLOPT_POSTFIELDS, $vars);
> curl_setopt($ch2, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
> curl_setopt($ch2, CURLOPT_REFERER, 'somewhere.com');
> curl_setopt($ch2, CURLOPT_COOKIE, "JSESSIONID=$SID");
> curl_setopt($ch2, CURLOPT_COOKIEJAR, 'cookies.txt');
> curl_setopt($ch2, CURLOPT_COOKIEFILE, 'cookies.txt');
> curl_setopt($ch2, CURLOPT_VERBOSE, 1);
> curl_setopt($ch2, CURLOPT_HEADER, 1);
> curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1);
> $curl_result = curl_exec ($ch2);
>
>
> Please could someone show me a curl method that retains or at least
returns
> them in the result ?
> I cant get the session id to show up anywhere ? any suggestions that
someone
> has used to set session cookies ?
> really i just need to retrieve the session cookie being set.
>
> i have it working if i go to the page with my real browser. prompt for the
> cookie variable to ask. grab the value from it there, then paste it to my
> code (as $SID var) and run my script in the same window i just used to get
> the sid. but i need to automate grabbing that SID from the first block.
>
> Thanks,
> Joel Colombo
>
>