FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » php curl only saves a cookie with tempnam()
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: php curl only saves a cookie with tempnam() [message #180766 is a reply to message #180760] Sun, 17 March 2013 06:46 Go to previous messageGo to previous message
doug[1] is currently offline  doug[1]
Messages: 10
Registered: March 2013
Karma:
Junior Member
Here's the whole function.

Two things I dont get, why does the curl_setopt use the $tmpfile that I set first and not the overwritten one. And, even if I comment the tempnam() $tmpfile, it wont write a cookie to /tmp/CURL_var_.txt. No cookie gets written at all, or at least not in the tmp dir. Both local Win and live Linux server.

function curl($url, $referer = null, $post = null, $removeWhiteSpaces = true) {
global $cost, $cost, $last_url;
if(is_array($referer)){//must be an args array
extract( wp_parse_args( $referer, array(
'referer' => null
,'post' => null
,'removeWhiteSpaces' => true
,'caller' => 'nocaller'
) ) );
}
if($removeWhiteSpaces)$url = removeWhiteSpaces($url);

static $tmpfile;

if(!isset($tmpfile) || ($tmpfile == ''))
$tmpfile = tempnam('/tmp', 'CURL_tmpfile');

$tmpfile = '/tmp/CURL_var_.txt';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfile);


@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061024 BonEcho/2.0");

if($referer) curl_setopt($ch, CURLOPT_REFERER, $referer);

if(!is_null($post)){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}

$html = curl_exec($ch);

$last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

curl_close($ch);
return $html;
}
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: all done
Next Topic: validation of a text box input...
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 21:29:09 GMT 2024

Total time taken to generate the page: 0.04284 seconds