Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    10
    Thanked 0 Times in 0 Posts

    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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    iman (01-28-2013)

  • #3
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    iman (01-28-2013)

  • #5
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    iman (01-29-2013)

  • #7
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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?

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    iman (01-29-2013)

  • #9
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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 Attached Files
    Last edited by iman; 01-29-2013 at 07:49 PM.

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    iman (01-30-2013)

  • #11
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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);    
            }
        }
    ?>

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    iman (01-30-2013)

  • #13
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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

  • #14
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    iman (01-30-2013)

  • #15
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •