I am trying to get an chart image from a remote site.
But the image seemed to be created dynamically from the site when called.
It will return nothing when not logged in.
This is the image URL
<img src="http://fuelbuyer.dtn.com/energy/view/energy/chart.do?width=150&height=120&chartType=0&ts=1352196066175&rackId=446&productId=179&points=8&showExtraLine=True">
I somehow managed to log in using this CODE and tried to display image.
But it is not working.
$ch = curl_init();
$url = 'http://fuelbuyer.dtn.com/energy/common/signin.do?';
$login = 'username=$USER&password=$pass&autoLogin=true&partnerId=0&partnerName=';
curl_setopt($ch, CURLOPT_URL, $url.$login);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
Calling the image URL directly (on browser Addressbar ONLY WHEN LOGGED IN) , will give some code like
”
‰PNG IHDR–xŸ-œGPIDATxÚílÇÇ IHKB-ËuÄØª!Eš°Š !ÈB IÀµ©…œ€ $@S‡8¶ ªÀ”D²œÐbR Æ`˜WjAx;~Äø…ç·ï±;³ýÎk×ûºÙݳ™»Þ_+´Ü÷v÷·3óÿf¾™òqnAa@„ùÂM›6åÔ5}£¡k訚Ži踶¾USž†Nh(_M’5tJC Á™°‚ðN?ÿ¼3>¾=5µîòåêÕô©V¢:‰ê%º+QƒD5õ©Y”›D-Õ*Q›Dí}ê¨S¢.‰º%²Kä蓳۹“߸ÑUPà’ˆ“ˆ—õéôéÓ!rBP¸¡Ÿÿ¼®¨¨F”ïò“”´ÂOŠÐ4?G}=ŽŠ”×ÎgdPòc!† #—[WB}
“
but when called like
<img src="http://fuelbuyer.dtn.com/energy/view/energy/chart.do?width=150&height=120&chartType=0&ts=1352196066175&rackId=446&productId=179&points=8&showExtraLine=True">
will give the correct image.
I really dont know what to do next.
How can I log into the site using cURL and execute this line.
<img src="http://fuelbuyer.dtn.com/energy/view/energy/chart.do?width=150&height=120&chartType=0&ts=1352196066175&rackId=446&productId=179&points=8&showExtraLine=True">
The site will be redirected to the home page when successfully logged in.
So, I have to prevent from redirection too.
The session will be terminated after few seconds.
Thanking you in advance,
Eugine P J
I got it working. Refer this comment.
Unable to fetch my schedule data from my schools site. Login with cURL wont work
The image you received with cURL is correct (see, you get a PNG header).
If you want to display it on a page of yours – let’s ignore licensing issues here – you need to put your scraping code, above, in a page of its own, e.g.
myimage.php.Then in your HTML code you put
and in the
myimage.php, once you have$output, you just output it:For the sordid details of more complicated login schemes, see the answer to How can I scrape website content in PHP from a website that requires a cookie login?