I am newbie to drupal and I am trying to create a custom module to get the content of page using curl functionality but it is not displaying anything (except:: the title i.e My Curl Demo).Below is the code that I am trying to develop,also attaching the screenshot of the page that I am getting instead of the content.

<?php
/**
* @file
* Implementation of hook_menu().
*/
function mycurl_menu() {

$items['mycurl'] = array(
'title' => 'My curl demo',
'page callback' => 'mycurl_curl',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}

function mycurl_curl() {

$user_agent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36";
$postdata ="name=abhilash&pass=abhilash";
$options = array(

CURLOPT_USERAGENT => $user_agent,
CURLOPT_COOKIEFILE => "cookie.txt",
CURLOPT_COOKIEJAR => "cookie.txt",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postdata,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 10,
);

$url = "http://localhost/drupal_commerce/product";

$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );

$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;

}

CommentFileSizeAuthor
2014-12-01_11-31_My curl demo.jpg56.83 KBAnonymous (not verified)

Comments

nevets’s picture

This seems to be the exact question asked at https://www.drupal.org/node/2384431. Why should we not consider this spam?