List Info

Thread: note 76047 added to function.curl-setopt




note 76047 added to function.curl-setopt
user name
2007-06-27 13:18:01
Two things that I noted, one of which has been mentioned
earlier, if you are connecting to an SSL site (https) and
don't have the appropriate certificate, don't forget to set
CURLOPT_SSL_VERIFYPEER as "false"... it's set to
"true" by default. Scratched my head over 2 hours
to figure this one out as I had a machine with an older
version installed and everything worked fine without using
this option on that one - but failed on other machines with
newer versions.

Second very important thing, I've never had my scripts work
(tried on various machines, multiple platforms) with a
Relative path to a COOKIEJAR or COOKIEFILE. In my experience
I HAVE to specify the absolute path and not the relative
path. 

Small script I wrote to connect to a page, gather all
cookies into a jar, connect to another page to login, taking
the cookiejar with you for authentication:

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR,
"/Library/WebServer/Documents/tmp/cookieFileName")
;
curl_setopt($ch, CURLOPT_URL,"htt
ps://www.example.com/myaccount/start.asp");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
ob_start();      // Prevent output
curl_exec ($ch);
ob_end_clean();  // End preventing output
curl_close ($ch);
unset($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"field1=".$f1."&field2=".$f2."&
amp;SomeFlag=True");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE,
"/Library/WebServer/Documents/tmp/cookieFileName")
;
curl_setopt($ch, CURLOPT_URL,"htt
ps://www.example.com/myaccount/Login.asp");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec ($ch);
curl_close ($ch);
----
Server IP: 64.71.164.2
Probable Submitter: 24.97.146.27
----
Manual Page -- http://www.php.net/manual/en/function.curl-setopt.php
Edit        -- https://master
.php.net/note/edit/76047
Del: integrated  -- h
ttps://master.php.net/note/delete/76047/integrated
Del: useless     -- http
s://master.php.net/note/delete/76047/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/76047/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/76047/spam
Del: non-english -- 
https://master.php.net/note/delete/76047/non-english
Del: in docs     -- http
s://master.php.net/note/delete/76047/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/76047
Reject      -- https://mast
er.php.net/note/reject/76047
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )