0

In Drupal I am logged in as a user. If I use my super cool drupal curl function:

function formtocart_graburl($url) {
$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_HEADER, 0);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
$output = curl_exec($ch);  
return $output;
}

to grab any url, it returns the content as if though I'm not logged in. How can I force CURL to think I am logged in as the user calling this function?

UPDATE

Assume the following:

  1. I am logged in at http://mydmomain.com/drupal
  2. I can access http://mydmomain.com/drupal/admin as I am an admin user
  3. When I am logged in, I try to grab the URL: http://mydmomain.com/drupal/admin, but it returns content that says I am not logged in.
  4. I would like curl to think I am logged in as the user I am logged into on Drupal

I assume the solution has something to do with grabbing the cookie or the sessions details and passing it to the curl function somehow?

4

1 回答 1

0

似乎您的问题,至少是措辞的方式,对用户如何处理调用的函数以及如何登录 Drupal 站点有点困惑;也就是说,应用程序级用户和服务器级用户之间的区别。

一般来说,您不会在 Drupal 中以用户身份运行代码。虽然您可以分配执行包含该函数的 Drupal 挂钩的权限,但它不会该用户身份执行,但用户 Drupal 本身正在以例如 www-data 的身份运行。

如果您真的只想将对该代码的访问控制权限授予 Drupal 的 ACL 系统,那么您应该阅读 hook_permission() 的 API 文档:

https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_permission/7

如果您没有明确实现 hook_permission,那么是的,这将允许该函数像您所说的那样“匿名”运行。

于 2013-06-14T04:36:09.740 回答