How to display cacti graph in a page using php and curl

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
shanil
Posts: 1
Joined: Thu Nov 13, 2014 11:54 pm

How to display cacti graph in a page using php and curl

Post by shanil »

Hi,

I am trying to display the cacti graph in my page using php and curl but it seems its not showing the image or if we use direct img source as the url then i will display graph image only when we logged in the cacti otherwise it won't display. I am using the following code, could you please check if anything wrong

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, '<url>/cacti/index.php');
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_HEADER, false);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'action=login&login_username=admin&login_password=admin');
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$store = curl_exec ($ch);
curl_setopt($ch, CURLOPT_URL, '<url>/cacti/graph_image.php?local_graph_id=740&rra_id=0');
$content = curl_exec ($ch);
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
header('Content-Type: image/png');
readfile("<url>/cacti/graph_image.php?local_graph_id=740&rra_id=0");
exit;
}
//Close CURL
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests