I just dragged the link out here. You look alright, this is what I see:
Code:
Connecting to mail.opi.yahoo.com
Sending request: GET /online?u=iman_rush&m=a&t=1 HTTP/1.1
Host: mail.opi.yahoo.com
Connection: Close
Response received: HTTP/1.1 200 OK
Date: Wed, 30 Jan 2013 02:48:43 GMT
P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
Expires: Thu, 05 Jan 1995 22:00:00 GMT
Cache-Control: private
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
Content-Type: text/plain; charset=utf-8
2
00
0
Which means it is pulling the "status" as 00.
If you are calling from /index.php the file in /files/ym/status.php, and it is opening the ./icons/00/icon.gif, than the problem here is that the filepath is incorrect. The filepath to the icon is under /files/ym/icons/00/icon.gif, but from the index, this path will resolve to /icons/00/icon.gif, which means you aren't getting the file you need.
Go back to the previous code you had without the printf's in it, and change this: $file = './icon/'.$sStatus.'/'.$_GET['img'].'.gif'; // This $_GET['img'] isn't really the most secure. Perhaps a switch validation should be used. to this: $file = __DIR__ . '/./icon/'.$sStatus.'/'.$_GET['img'].'.gif'; // This $_GET['img'] isn't really the most secure. Perhaps a switch validation should be used. and see if that does the trick.
I'm still curious as to why the file_get_contents is used directly within the status on the original code, but I have to find it as the second line of the body.
Edit:
Actually, your problem may be even easier than this:
So what is in $sStatus immediately before calling the is_file check? The only tests I've run indicate that it is 00 that I get, but that doesn't mean you get the same depending on your results (since I also get the page cannot be found when I provide it with the headers to mock the browser).
I'm wondering if it needs more header information since I do get differing information based on what it is given.
$file = './icon/'.$sStatus.'/'.$_GET['img'].'.gif'; // This $_GET['img'] isn't really the most secure. Perhaps a switch validation should be used. if(is_file($file)) { header("Content-type: image/gif"); readfile($file); } }
It works now but there is a tiny problem. The page takes a bit longer time to load !
BTW, what does this code do?
PHP Code:
if(is_file($file))
Because although i comment it, the script still works!
It will work so long as the file exists.
That code's job is to make sure it is available. Without an else clause though, it carries little meaning since the script itself will be used in the scope of an img tag or a renderable image type, so without an else clause to provide it with an alternate image to work with, it will create a broken image link regardless of if the is_file is used or not and the file doesn't exist.
It will work so long as the file exists.
That code's job is to make sure it is available. Without an else clause though, it carries little meaning since the script itself will be used in the scope of an img tag or a renderable image type, so without an else clause to provide it with an alternate image to work with, it will create a broken image link regardless of if the is_file is used or not and the file doesn't exist.
So you mean it's better to enable this line or disable ?
PHP Code:
if(is_file($file))
However, The script which i'm using now is:
PHP Code:
<?php $sDomain = 'mail.opi.yahoo.com'; $iTimeout = 10; $sStatus = '00'; // I'd actually recommend defaulting this to whatever the "offline" status is. if (isset($_GET['id'], $_GET['img'])) { if ($fh = @fsockopen($sDomain, 80, $errno, $errstr, $iTimeout)) { $sResult = ''; $sWrite = "GET /online?u={$_GET['id']}&m=a&t=1 HTTP/1.1\r\n"; $sWrite .= "Host: $sDomain\r\n"; $sWrite .= "Connection: Close\r\n\r\n"; fwrite($fh, $sWrite); while (!feof($fh)) { $sResult .= fread($fh, 128); } list($header, $body) = explode("\r\n\r\n", $sResult); $aHeaders = explode("\r\n", $header); // optional, can scanf off of the regular string sscanf($aHeaders[0], 'HTTP/1.1 %d %s', $code, $httpStatus); if ($code == 200) { // Now, this is what I'm not sure about. The status you have in the directories match this, but I'm not sure why it differs from the file_get_content. $aBody = explode("\n", $body); $sStatus = isset($aBody[1]) ? $aBody[1] : '00'; } fclose($fh); } if ($sStatus == 01) { $file = './icon/01/icon.gif'; } else { $file = './icon/00/icon.gif'; }
If its working, it much further ahead yeah.
This won't work, at least not the way it's supposed to: if ($sStatus == 01). It *will* work because of PHP's datatype weakness, but it won't work logically since you are comparing a string '01' to octal 01. With the datatype weakness this compares 1 to 1. I'd suggest keeping them as string comparisons though.
I'd also still use the is_file check, but provide a hard coded alternative path for just in case it cannot find the file you have specified.