duaj39673 2013-04-01 11:50
浏览 121

通过curl和浏览器登录

I'm working with drupal 7 and REST api. I'd like to log in into drupal with curl and later when i visit the website with a browser i want to be logged in.

i'm usin gthis code:

<?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);

?>

And it works pretty well, it logs the user in, but when i visit "example.com" i'm not logget in as "usertest". Is there any way to log me into Drupal and allow me to access with a browser?

The goal is to log me in into many website with the same users when i log in into one as i wrote here (Same webserver, same drupal, same db, single sign on?).

  • 写回答

1条回答 默认 最新

  • dongzhi6463 2013-04-01 11:56
    关注

    Ok, i found a solution here: Login to website through CURL and client browser

    Use curl cookies for the user browser is pretty impossible..

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧