如何设置用curl编写的cookie jar的权限?

时间:2012-09-17 18:12:17

标签: php curl

我怎么能,或者甚至可以改变curl写入cookie jar文件的权限?我正在尝试检索会话cookie [用于sso插件]并且可以写入cookie文件,但是当我去阅读文件时,权限是600&我无法打开文件来解析内容....基本上我需要将权限设置为644。

<?php


$username = 'xxxxxxxxxxx';
$password = 'xxxxxxxxxxxxxxx';

$ckfile = tempnam("./", "MOODCOOKIE_");

//set POST variables
$url = 'http://domain.com/login/index.php';
$fields_string = 'username='.$username.'&password='.$password.'&rememberusername=1&Login';
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

//curl_setopt($ch,CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch,CURLOPT_AUTOREFERER, true );


//execute post
$content = curl_exec($ch);
$response = curl_getinfo( $ch );

echo '<br /><pre>';
print_r($response);
echo '<br /></pre>';

$file_handle = fopen($ckfile, "r");

while (!feof($file_handle)) {
   $line = fgets($file_handle);
   echo $line.'<br />';
}
fclose($file_handle);



//close connection
curl_close($ch);

return $yourcookie;

?>

1 个答案:

答案 0 :(得分:1)

chmod不起作用?

chmod($ckfile,0644);

http://ar2.php.net/manual/es/function.chmod.php