Hi guys,

I have the following script that was written to generate a "master code" for a system I'm working on. The script basically accepts 2 inputs, does a number of sums and then outputs the master code. The problem, however, is that I've just switched servers and the script was working perfectly on the old server, but I now get an "overflow" error on the new server (from line 28 of the script). Does anyone have any thoughts on what could possibly have changed from the old to the new server that's causing this to happen?

Thanks in advance!

<?php
// int sum
// char p
// int len
function slow_crc32($sum, $p, $len) {
	$POLY = 0x04C11DB7;
	$j=0;
	while($len--) {
		$byte = ($p[$j]===0) ? 0 : ord($p[$j]);
		$j++;
		//echo "byte is: $byte<br/>";
		for ($i=0; $i<8; ++$i) {
			$osum = $sum;
			$sum <<= 1;
			$res = $byte & 0x80;

		if ($res) {
			$sum |= 1;
		}
		$res = $osum & 0x80000000;

		if ($res) {
			$sum ^= $POLY;
		}

		if ($sum > 4294967295) {
			echo "overflow<br/>";
		}
		$byte <<= 1;
	}
}
return ($sum);
}

function GenerateMasterCode($message, $imei, &$code) {

$crc = 0xAABAD666;
$buf = array(0,0,0,0);

if (strlen($message)==0) {
	return false;
}
if (strlen($imei)==0) {
	return false;
}
if (strlen($message)>127) {
	return false;
}
if (strlen($imei)>127) {
	return false;
}

$crc = slow_crc32($crc, $imei, strlen($imei));
$crc = slow_crc32($crc, $buf, 4);
$crc = slow_crc32($crc, $message, strlen($message));
$crc = slow_crc32($crc, $buf, 4);

//WordToHex($code, $crc);
$code = str_pad(strtoupper(dechex($crc)), '8', $pad_string = "0", $pad_type = STR_PAD_LEFT);
}
?>

    Hi,

    Probably they have diferent PHP versions...

    Also check diferences on php.ini

    It is better to check that, then check whats diferent on the functions you use.

      I've determined that the new server is 64-bit, whereas the old one was 32-bit. Does anyone have a possible fix for me with regards to this script?

        Write a Reply...