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-28-2013, 01:08 AM   PM User | #1
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
Alternative code for Y! status

I've just moved to new server and got this error due to webmaster has disabled this function(because of security reasons):

PHP Code:
Warningfile_get_contents() [function.file-get-contents]:
URL file-access is disabled in the server configuration in /home/public_html/files/ym/status.php on line 3 
Here is the content of status.php:
PHP Code:
<?php
if(!empty($_GET['id']) || !empty($_GET['img']) ) {
$status file_get_contents("http://mail.opi.yahoo.com/online?u=".$_GET['id']."&m=a&t=1");
$file './icon/'.$status.'/'.$_GET['img'].'.gif';
if(
is_file($file)) {
header("Content-type: image/gif");
readfile($file);
}
}
?>
Does any one can help me out to change this function or create new code to do so?

-------
More information:

I put this code into index.html to call status.php

PHP Code:
<a href="ymsgr:sendim?yahooID"><div id="product" style="background:url(ym/status.php?id=yahooID&amp;img=sup1) 0 0 no-repeat;"
I appreciate sharing your knowledge

P.S.
I've attached entire of /ym folder

Last edited by iman; 01-30-2013 at 12:50 AM..
iman is offline   Reply With Quote
Old 01-28-2013, 03:09 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 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
The easiest thing to do is to ask your host to open up the PHP directive allow_url_fopen. That is how PHP is able to issue an fopen (or any sub-variation of it including file_get_contents() and file()) over an http:// protocol instead of a file:// protocol. Baring that, you can use either curl library or directly invoking sockets to connect remotely. Curl can easily be disabled by simply not configuring it, while sockets are the least likely to be closed since they take explicit commanding on the denied functions list.
If they refuse to open the allow_url_fopen directive, than check if your sockets are available:
PHP Code:
$rf = new ReflectionFunction("fsockopen");
printf("fsockopen is available? %s" PHP_EOL, ($rf->isDisabled() ? 'no' 'yes')); 
If that says its available, you should be able to use sockets for this.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
iman (01-28-2013)
Old 01-28-2013, 06:39 PM   PM User | #3
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:
The easiest thing to do is to ask your host to open up the PHP directive allow_url_fopen.
They said they won't enable it because of security reasons !!! Thay also said Curl is enabled.

I got this output:
fsockopen is available? yes

As i'm an amateur in coding, could you change the above code to sockes please?
I would appreciate your help as i'm really stuck in it

Last edited by iman; 01-28-2013 at 06:54 PM..
iman is offline   Reply With Quote
Old 01-28-2013, 08:23 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 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
Yep, I can't test it out where I am though.
PHP Code:
<?php

$sDomain 
'mail.opi.yahoo.com';
$iTimeout 10;
$sStatus ''// 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);
        }
        
$sStatus = !empty($sResult) ? $sResult $sStatus;
        
fclose($fh);
    }

    
$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);    
    }
}
Try that.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
iman (01-28-2013)
Old 01-28-2013, 11:25 PM   PM User | #5
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 did, but nothing happened(Still blank). I'm going to inbox you my server details.
I'm so sorry for bothering you but you're the only person who can help me out

Last edited by iman; 01-28-2013 at 11:29 PM..
iman is offline   Reply With Quote
Old 01-29-2013, 12:00 AM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 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
That won't really help me.
What will help is if you tell me what the $status is you can get back from them. I kinda forgot that with sockets you'll need to strip the headers out from the return result, so I doubt you have a status that looks exactly like this:
Code:
HTTP/1.1 200 OK
Date: Mon, 28 Jan 2013 23:57:25 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
I don't know what the 2, 00, or 0 stand for in their results. Getting there would be easy, but its not knowing what the linefeeds between the numbers represent.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
iman (01-29-2013)
Old 01-29-2013, 03:29 PM   PM User | #7
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
That won't really help me.
What will help is if you tell me what the $status is you can get back from them. I kinda forgot that with sockets you'll need to strip the headers out from the return result, so I doubt you have a status that looks exactly like this:
Code:
HTTP/1.1 200 OK
Date: Mon, 28 Jan 2013 23:57:25 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
I don't know what the 2, 00, or 0 stand for in their results. Getting there would be easy, but its not knowing what the linefeeds between the numbers represent.
Sadly, I didn't get anything from $status. Can you check your PM box please?
iman is offline   Reply With Quote
Old 01-29-2013, 06:35 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 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 need to know what directories you have since you use the status here: $file = './icon/'.$status. . .. That $status is what the content body is of the file_get_contents, but with the socket run I have I don't have a valid messenger to give it so all it gives me back is 2\n00\n0, and I don't know what that means in combination with the $status directories you have.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
iman (01-29-2013)
Old 01-29-2013, 07:02 PM   PM User | #9
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
Here is the path:

The online icon is here
/ym/icon/01/icon.gif

And the offline icon is here
/ym/icon/00/icon.gif

I attached the entire of /ym folder
Attached Files
File Type: zip ym.zip (25.0 KB, 9 views)

Last edited by iman; 01-29-2013 at 07:49 PM..
iman is offline   Reply With Quote
Old 01-29-2013, 09:02 PM   PM User | #10
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 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
Just the two expected?
Replace this:
PHP Code:
        $sStatus = !empty($sResult) ? $sResult $sStatus;
        
fclose($fh); 
With this:
PHP Code:
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); 
And near the top set the default value of $sStatus to '00' as a string.

Try that.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
iman (01-30-2013)
Old 01-30-2013, 12:28 AM   PM User | #11
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 did but still not working...

that's what i did:
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);
        }
        
        
$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);    
        }
    }
?>
iman is offline   Reply With Quote
Old 01-30-2013, 02:15 AM   PM User | #12
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 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
k, put in some logging and attach to the script directly:
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']))
    {
printf("Connecting to %s" PHP_EOL$sDomain);
        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";
printf("Sending request: %s" PHP_EOL$sWrite);
            
fwrite($fh$sWrite);
            while (!
feof($fh))
            {
                
$sResult .= fread($fh128);
            }
printf("Response received: %s" PHP_EOL$sResult);
            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);
        }
        else
        {
printf("Failed to connect: %s (%d)" PHP_EOL$errstr$errno);
        }
        
        
$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);    
        
}
    }
What's the output from that? Drag it up from the resulting HTML source since it has linefeeds to format it.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
iman (01-30-2013)
Old 01-30-2013, 02:37 AM   PM User | #13
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 above code with the previous one in status.php but still not working
The page source for ~/status.php is only number 1
iman is offline   Reply With Quote
Old 01-30-2013, 02:41 AM   PM User | #14
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 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
Quote:
Originally Posted by iman View Post
I replaced above code with the previous one in status.php but still not working
The page source for ~/status.php is only number 1
Did you give it the querystring for the id and img as well?
I'm not sure where the 1 is coming from though. The only output we have is textual.

Edit:
BTW, give it a valid id. You can remove it from the source that you post back, it'll be in the part that we're sending to the server.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
iman (01-30-2013)
Old 01-30-2013, 02:47 AM   PM User | #15
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'm using these codes in index.html to call ~/status.php but nothing's happening

PHP Code:
<a style="text-decoration:none;" href="ymsgr:sendim?iman_rush"><img src="./files/ym/status.php?id=iman_rush&amp;img=icon"  style="border:0px;"/> 
and the second one is:
PHP Code:
<a href="ymsgr:sendim?iman_rush"><div id="product" style="background:url(./files/ym/status.php?id=iman_rush&amp;img=icon) 0 0 no-repeat;"

Last edited by iman; 01-30-2013 at 02:51 AM..
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 04:13 PM.


Advertisement
Log in to turn off these ads.