Hello every body,

I'm using this code to load a node from my front page and i'm getting

You are not authorized to access this page.

function get_webpage_content($webpage_url)
{
    $curl_handle=curl_init();
    curl_setopt($curl_handle,CURLOPT_URL,$webpage_url);
    curl_setopt($curl_handle,CURLOPT_TIMEOUT,10);
    //curl_setopt($curl_handle,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
    curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,10);
    curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
    $html = curl_exec($curl_handle);
    curl_close($curl_handle);
     
    return $html;
}

and call the function in front page like this :

echo get_webpage_content('http://localhost/site/fr/node/423');

and i'm getting You are not authorized to access this page.

Have i missing something in my script ?

Thank you for your help

Comments

jason_gates’s picture

Hi,
You need to login via curl. Curl needs it's own session.
......
Instruct curl to post the login info, manage cookie etc.

stomerfull’s picture

Hello thank you for your reply

I found the solution i have just check permission in admin/user/permissions and its works

Thank you

chuey’s picture

I'm using the following code using cURL to login to Drupal 7. It logs me in OK, but I can only view one page. If I click on any subsequent links, it seems I lose the session and now I'm an anonymous user. What do I have to do to stay logged in?

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://mysite.com/user/login");
curl_setopt($ch, CURLOPT_HEADER, 1);  
curl_setopt($ch, CURLOPT_USERAGENT,'PHP script');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "name=siteusername&pass=sitepassword&form_id=user_login");

ob_start();
curl_exec ($ch);
curl_close ($ch);
unset($ch);

?>

I appreciate any help.

da_solver’s picture

Hi,
Why are you calling curl_close()?

Where are you calls to other Drupal services?

Why are posting a curl question in a forum for developing Drupal modules?

Are you developing a Drupal module?