Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2013, 02:57 AM   PM User | #16
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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:
Code:
<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Yahoo!</title><meta name="ROBOTS" content="NOINDEX" /><style>
/* nn4 hide */ 
/*/*/
body {font:small/1.2em arial,helvetica,clean,sans-serif;font:x-small;text-align:center;}table {font-size:inherit;font:x-small;}
html>body {font:83%/1.2em arial,helvetica,clean,sans-serif;}input {font-size:100%;vertical-align:middle;}p, form {margin:0;padding:0;}
p {padding-bottom:6px;margin-bottom:10px;}#doc {width:48.5em;margin:0 auto;border:1px solid #fff;text-align:center;}#ygma {text-align:right;margin-bottom:53px}
#ygma img {float:left;}#ygma div {border-bottom:1px solid #ccc;padding-bottom:8px;margin-left:152px;}#bd {clear:both;text-align:left;width:75%;margin:0 auto 20px;}
h1 {font-size:135%;text-align:center;margin:0 0 15px;}legend {display:none;}fieldset {border:0 solid #fff;padding:.8em 0 .8em 4.5em;}
form {position:relative;background:#eee;margin-bottom:15px;border:1px solid #ccc;border-width:1px 0;}
#s1p {width:15em;margin-right:.1em;}
form span {position:absolute;left:70%;top:.8em;}form a {font:78%/1.2em arial;display:block;padding-left:.8em;white-space:nowrap;background: url(http://l.yimg.com/a/i/s/bullet.gif) no-repeat left center;} 
form .sep {display:none;}.more {text-align:center;}#ft {padding-top:10px;border-top:1px solid #999;}#ft p {text-align:center;font:78% arial;}
/* end nn4 hide */
</style></head>
<body><div id="doc">
<div id="ygma"><a href="http://us.rd.yahoo.com/default/*http://www.yahoo.com"><img src=http://l.yimg.com/a/i/yahoo.gif width=147 height=31 border=0 alt="Yahoo!"></a><div><a href="http://us.rd.yahoo.com/default/*http://www.yahoo.com">Yahoo!</a> - <a href="http://us.rd.yahoo.com/default/*http://help.yahoo.com">Help</a></div></div>
<div id="bd"><h1>Sorry, the page you requested was not found.</h1>
<p>Please check the URL for proper spelling and capitalization. If you're having trouble locating a destination on Yahoo!, try visiting the <strong><a href="http://us.rd.yahoo.com/default/*http://www.yahoo.com">Yahoo! home page</a></strong> or look through a list of <strong><a href="http://us.rd.yahoo.com/default/*http://docs.yahoo.com/docs/family/more/">Yahoo!'s online services</a></strong>. Also, you may find what you're looking for if you try searching below.</p>
<form name="s1" action="http://us.rd.yahoo.com/default/*-http://search.yahoo.com/search"><fieldset>
<legend><label for="s1p">Search the Web</label></legend>
<input type="text" size=30 name="p" id="s1p" title="enter search terms here">
<input type="submit" value="Search">
<span><a href="http://us.rd.yahoo.com/default/*http://search.yahoo.com/search/options?p=">advanced search</a> <span class=sep>|</span> <a href="http://us.rd.yahoo.com/default/*http://buzz.yahoo.com">most popular</a></span>
</fieldset></form>
<p class="more">Please try <strong><a href="http://us.rd.yahoo.com/default/*http://help.yahoo.com">Yahoo! Help Central</a></strong> if you need more assistance.</p>
</div><div id="ft"><p>Copyright &copy; 2006 Yahoo! Inc. All rights reserved. <a href="http://us.rd.yahoo.com/default/*http://privacy.yahoo.com">Privacy Policy</a> - <a href="http://us.rd.yahoo.com/default/*http://docs.yahoo.com/info/terms/">Terms of Service</a></p></div>
</div></body></html>
That indicates the link for /online is no good.

__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 

Last edited by Fou-Lu; 01-30-2013 at 03:08 AM..
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
iman (01-31-2013)
Old 01-31-2013, 01:10 AM   PM User | #17
iman
New Coder

 
Join Date: Jan 2013
Posts: 12
Thanks: 10
Thanked 0 Times in 0 Posts
iman is an unknown quantity at this point
I found what the problem is.
I changed
PHP Code:
$file './icon/'.$sStatus.'/icon.gif'
to
PHP Code:
$file './icon/'.'00'.'/icon.gif'
to check this path: "./icon/00/icon.gif". the indicator was displayed. It means the problem is from
PHP Code:
$sStatus 
Its result cannot be retrieved

Last edited by iman; 01-31-2013 at 06:31 PM..
iman is offline   Reply With Quote
Old 01-31-2013, 09:44 PM   PM User | #18
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Old 01-31-2013, 11:39 PM   PM User | #19
iman
New Coder

 
Join Date: Jan 2013
Posts: 12
Thanks: 10
Thanked 0 Times in 0 Posts
iman is an unknown quantity at this point
I replaced these codes:
PHP Code:
if ($sStatus == 01)
        {
        
$file './icon/01/icon.gif';
        }
        else
        {
        
$file './icon/00/icon.gif';
        }
        
//      if(is_file($file))  {
            
header("Content-type: image/gif");
            
readfile($file);
//         } 
With:
PHP Code:
$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!

Last edited by iman; 01-31-2013 at 11:56 PM..
iman is offline   Reply With Quote
Old 02-01-2013, 12:12 AM   PM User | #20
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
iman (02-01-2013)
Old 02-01-2013, 12:34 AM   PM User | #21
iman
New Coder

 
Join Date: Jan 2013
Posts: 12
Thanks: 10
Thanked 0 Times in 0 Posts
iman is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
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($sDomain80$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($fh128);
            }
            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(is_file($file)) {
            
header("Content-type: image/gif");
            
readfile($file);
        
//}
    
}
?>
do you confirm this suitable to use?
iman is offline   Reply With Quote
Old 02-03-2013, 02:45 PM   PM User | #22
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
iman (02-04-2013)
Old 02-04-2013, 01:11 AM   PM User | #23
iman
New Coder

 
Join Date: Jan 2013
Posts: 12
Thanks: 10
Thanked 0 Times in 0 Posts
iman is an unknown quantity at this point
Thank you very much. I really appreciate your kindness.
iman is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:53 AM.


Advertisement
Log in to turn off these ads.