采用curl时候, Safari下cookie异常

基于wordpress,开发了一个插件,用户权限还是基于wordpress。
因此,必须增加一个权限验证接口islogin.php,以判断用户是否登录。

 1 function check_login(){
 2     $current_url = ( is_ssl() ? 'https://' : 'http://' ) .
 3                         $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 4     $islogin_url = preg_replace("/\/trial\/.*/is", "/is-login.php?sn=".
 5                       time(), $current_url);
 6     $ch = curl_init();
 7     curl_setopt($ch, CURLOPT_POST, FALSE);
 8     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 9     curl_setopt($ch, CURLOPT_URL, $islogin_url);
10     /*如果加上这个请求头
11      1.PHP 5.3.5-1ubuntu7.7 with Suhosin-Patch (cli) , Safari下就会异常。
12      2.PHP 5.3.2-1ubuntu4.14 with Suhosin-Patch (cli) , Safari下又正常。
13      3.PHP 5.3.8 (cli) (built: Aug 23 2011 11:50:20), Safari下又正常。
14     */
15     //$headers = 'Set-Cookie: ';
16     foreach ( $_COOKIE as $cookieKey => $cookieVal ) {
17         $headers .= $cookieKey."=".urlencode($cookieVal)."; ";
18     }
19     $headers = substr($headers,0,-2) . "\r\n";
20     curl_setopt($ch, CURLOPT_COOKIE, $headers);
21     curl_setopt($ch, CURLOPT_POSTFIELDS, FALSE);
22     $data = curl_exec($ch);
23     curl_close($ch);
24     return $data != 1? false: true;
25 }
原文地址:https://www.cnblogs.com/uniqid/p/4154643.html