通过curl和浏览器登录

时间:2013-04-01 11:50:36

标签: php cookies curl drupal-7

我正在使用drupal 7和REST api。 我想使用curl登录drupal,稍后当我使用浏览器访问该网站时我想要登录。

我在使用这个代码:

<?php

$user_data = array(
  'username' => 'usertest',
  'password' => 'pass',
);
$ch = curl_init();
$tmpfname = dirname(__FILE__).'/'.$_COOKIE['PHPSESSID'].'.txt';
curl_setopt($ch, CURLOPT_URL, "http://example.com/networklogin/user/login");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $user_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $tmpfname );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $tmpfname );
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

?>

它工作得很好,它会记录用户,但是当我访问“example.com”时,我不会记录为“usertest”。 有没有办法让我登录Drupal并允许我使用浏览器访问?

目标是当我在此处(Same webserver, same drupal, same db, single sign on?)登录时,使用相同的用户登录我的许多网站。

1 个答案:

答案 0 :(得分:0)

好的,我在这里找到了一个解决方案: Login to website through CURL and client browser

对用户浏览器使用curl cookie是非常不可能的..

相关问题