Jump to content

Different results for same code in different PHP version??? help!


larttaus

Recommended Posts

Hi all,

I have the following code from a google page rank script checker, but I get different results depending upon which version of PHP I use. Why would there be a difference? Is it because of the PHP version? or what OS apache is sitting on? Has something altered in PHP that affects the way these functions  are calculated? - as two run on the same host just different php versions.

I have one version which works correctly, this is installed on my XP home box running apache 4.2.3 (phpdev)
I have another version which fails on my internet hosts server (RedHat) with apache 4.4.4
Another version which fails on my internet hosts server (RedHat) with apache 5.1.6
Lastly another working copy on my XP Home box running apache 5.2.0 (xampp)

The code that fails/changes is below:

[code]function zeroFill($a, $b)
{
echo "zeroFill: " . $a . " " . $b . "<br/>";
    $z = hexdec(80000000);
        if ($z & $a)
        {
            $a = ($a>>1);
            $a &= (~$z);
            $a |= 0x40000000;
            $a = ($a>>($b-1));
            echo "zeroFill: za<br/>";
        }
        else
        {
            $a = ($a>>$b);
            echo "zeroFill: a<br/>";
        }
        echo "zeroFill: " . $a . "<br/>";
        return $a;
}


function mix($a,$b,$c) {
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
echo $a . " $a<br/>"; // response up to here posted below
  $b -= $c; $b -= $a; $b ^= ($a<<8);
echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
echo $c . " $c<br/>";
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
echo $a . " $a<br/>";
  $b -= $c; $b -= $a; $b ^= ($a<<16);
echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
echo $c . " $c<br/>";
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));
echo $a . " $a<br/>";
  $b -= $c; $b -= $a; $b ^= ($a<<10);
echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
echo $c . " $c<br/>";

  return array($a,$b,$c);
}[/code]

To make things short I've only pasted part of the response (the first processed line from the mix function):

Apache Version: 4.2.3 / 5.2.0 (Working)
[code]zeroFill: 1520109454 13
zeroFill: a
zeroFill: 185560
-1655620743 -1655620743
[/code]

Apache Version: 4.4.4 (Fails)
[code]zeroFill: 5815076750 13
zeroFill: za
zeroFill: 524287
-2146959361 -2146959361[/code]

Apache Version: 5.1.6(Fails)
[code]zeroFill: 5815076750 13
zeroFill: a
zeroFill: 185560
-2147298088 -2147298088[/code]

Any help or comments would be much appreciated, from this quick test I'd say the OS affects the results, can I find anywhere I can download 4.4.4 or 5.1.6 to test on my XP box?

Kind Regards

Matthew
Link to comment
Share on other sites

[quote author=larttaus link=topic=122721.msg506510#msg506510 date=1168990844]
From this quick test I'd say the OS affects the results, can I find anywhere I can download 4.4.4 or 5.1.6 to test on my XP box?[/quote]

Give this a try...

http://museum.php.net/

Regards
Huggie
Link to comment
Share on other sites



The code is:
(also available as txt file: [url=http://ccgi.larttaus.plus.com/testfile.txt]http://ccgi.larttaus.plus.com/testfile.txt[/url]
[code]
<?php
define('GOOGLE_MAGIC', 0xE6359A60);

function zeroFill($a, $b)
{
echo "zeroFill: " . $a . " " . $b . "<br/>";
    $z = hexdec(80000000);
        if ($z & $a)
        {
            $a = ($a>>1);
            $a &= (~$z);
            $a |= 0x40000000;
            $a = ($a>>($b-1));
            echo "zeroFill: za<br/>";
        }
        else
        {
            $a = ($a>>$b);
            echo "zeroFill: a<br/>";
        }
        echo "zeroFill: " . $a . "<br/>";
        return $a;
}


function mix($a,$b,$c) {
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
echo $a . " $a<br/>";
  $b -= $c; $b -= $a; $b ^= ($a<<8);
echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
echo $c . " $c<br/>";
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
echo $a . " $a<br/>";
  $b -= $c; $b -= $a; $b ^= ($a<<16);
echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
echo $c . " $c<br/>";
  $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));
echo $a . " $a<br/>";
  $b -= $c; $b -= $a; $b ^= ($a<<10);
echo $b . " $b<br/>";
  $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
echo $c . " $c<br/>";

  return array($a,$b,$c);
}

function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
    if(is_null($length)) {
        $length = sizeof($url);
    }
    $a = $b = 0x9E3779B9;
    $c = $init;
    $k = 0;
    $len = $length;
    while($len >= 12) {
        $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
        $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
        $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));

        $mix = mix($a,$b,$c);
        $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
        $k += 12;
        $len -= 12;
    }
echo $a . " $a<br/>";
echo $b . " $b<br/>";
echo $c . " $c<br/>";

echo $mix . " $mix<br/>";
echo $k . " $k<br/>";
    $c += $length;
    switch($len)
    {
        case 11: $c+=($url[$k+10]<<24);
        case 10: $c+=($url[$k+9]<<16);
        case 9 : $c+=($url[$k+8]<<8);
        case 8 : $b+=($url[$k+7]<<24);
        case 7 : $b+=($url[$k+6]<<16);
        case 6 : $b+=($url[$k+5]<<8);
        case 5 : $b+=($url[$k+4]);
        case 4 : $a+=($url[$k+3]<<24);
        case 3 : $a+=($url[$k+2]<<16);
        case 2 : $a+=($url[$k+1]<<8);
        case 1 : $a+=($url[$k+0]);
    }
    $mix = mix($a,$b,$c);
    return $mix[2];
}

function strord($string) {
    for($i=0;$i<strlen($string);$i++) {
        $result[$i] = ord($string{$i});
    }
    return $result;
}

function getrank($url)
{
if (isset($_GET['url']) && !empty($_GET['url'])){
$url = 'info:'. $_GET['url'];
}
$ch = GoogleCH(strord($url));


}

if (isset($_GET['url']) && !empty($_GET['url'])){
    $url = $_GET['url'];
    $pr = getrank($url);

}

?>[/code]

Regards

Matthew
Link to comment
Share on other sites

[quote author=btherl link=topic=122721.msg506684#msg506684 date=1169012652]
My results for versions 4.4.2, 5.1.4 and 5.2.0 on linux match your "working" output.

Are you assuming 32-bit or 64-bit integer size in any of that code?
[/quote]

The honest reply would be not sure.... I am not too strong a PHP programmer...

Matthew
Link to comment
Share on other sites

Hmm.. well it "looks" like it depends on 32 bit integers.  A 64 bit OS could easily break it.  Can you find out from your hosting provider whether they run a 32 bit or 64 bit version of Red Hat?

If they do, then that's very likely the cause.  If not, then back to square one.
Link to comment
Share on other sites

I did some more testing with the full code, and it gives totally different results on a 64 bit system.  However it gives the same results on each of the different php versions I tried (4.3.10 & 5.1.4 on 32 bit system, 4.4.2, 5.1.4 and 5.2.0 on 64 bit).

The output I got on 64 bit systems was very large (like -8324662986662860468 instead of -781188683), so I'm pretty sure you have 32 bit ints on both your machine and the redhat servers.

So that just leaves the different OS.. I would believe that it gives different results on a different OS.  Maybe something in the code depends on a particular feature of that OS, or of PHP compiled on that OS.

Hmm.. it looks like it implements an encryption algorithm.  One solution may be to use a library to do the encryption rather than doing it in php.  That would be practical if you can find out what algorithm it is and what inputs it needs.  The mcrypt module might be able to help there.

Do you know what encryption algorithm it is?

One more question :)  What did you set url to when you got the output in your first post?  And where is that output from?  The first thing it printed out?
Link to comment
Share on other sites

I have moved the scripts to an accessible part of my website for the time being:

PHP5:
http://www.web-pages-directory.com/prcheck.php5?url=www.metrodata.co.uk

PHP4:
http://www.web-pages-directory.com/prcheck.php?url=www.metrodata.co.uk

The url in question tested was: www.metrodata.co.uk

Unfortunately I have no idea what the encryption algorithm is sorry
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.