Topic: Alternative for version check

I was messing around, and I realized that it was possible to do the version check with allow_url_fopen disabled using fsockopen.
My code:

if ($action == 'check_upgrade')
{
    if (!ini_get('allow_url_fopen'))
    {
        $latest_version = '';
        $fp = @fsockopen("www.punbb.org", 80, $errno, $errstr, 30);
            
        $out = "GET /latest_version HTTP/1.1\r\n";
        $out .= "Host: www.punbb.org\r\n";
        $out .= "Connection: close\r\n\r\n";
    
        fwrite($fp, $out);
        while (!feof($fp))
        {
            $latest_version .= trim(@fread($fp, 128));
        }
        $latest_version = explode("\n", $latest_version);
        $latest_version = array_pop($latest_version);
        @fclose($fp);
    }
    else
    {
        $fp = @fopen('http://punbb.org/latest_version', 'r');
        $latest_version = trim(@fread($fp, 16));
        @fclose($fp);
    }

Of course, you could use fsockopen for everything to simplify it.

Re: Alternative for version check

Well, I guess that's an option. One potential problem is that fsockopen() is disabled on a lot of hosts as well smile

"Programming is like sex: one mistake and you have to support it for the rest of your life."