我必须验证用户从wordpress到drupal。我正在使用php curl将用户名和密码传递给drupal用户登录URL并为每个用户设置随机cookie,但cookie不会在服务器中生成。
$ login_url ='http://xxxxx.com/drupal/user/login';
// Preparing postdata for wordpress login
$data = "name=". $username."&email=".$usermail."&pass=".$user_pass."&form_id=user_login&sso=1" ;
$cookie_file= '/xxx/yyy/serverpath/user_cookies/'.rand().'.txt';
// Intialize cURL
$ch = curl_init();
// Url to use
curl_setopt( $ch, CURLOPT_URL, $login_url );
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
// Set the cookies for the login in a cookie file.
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie_file );
// Set SSL to false
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
// User agent
curl_setopt( $ch, CURLOPT_USERAGENT, $http_agent );
// Maximum time cURL will wait for get response. in seconds
curl_setopt( $ch, CURLOPT_TIMEOUT, 60 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
// Return or echo the execution
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
// Set Http referer.
curl_setopt( $ch, CURLOPT_REFERER, $login_url );
// Post fields to the login url
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt( $ch, CURLOPT_POST, 1);
// Save the return in a variable
$content = curl_exec ($ch);
/*
** if you need to visit another url, you can do it here.
** curl_setopt( $ch, CURLOPT_URL, 'a new url address or a file download url' );
** $content = curl_exec ($ch);
*/
// Close the cURL.
curl_close( $ch );