Page 1 of 1

Code on Windows and Linux.

Posted: Sun Dec 10, 2006 4:59 pm
by ThichHeaded
Hello guys, I decided to take up the offer of a few people in the general area and try and learn php here.

This is going to be fun.. Anyway to the question.

I have a host that runs a site on Linux.

and I have a home server running on windows. using Wamp5.

I have a question or 2.

On the Linux server the php code is used to do a countdown type thing that I got off hotscripts or something like that 3 yrs ago..

The code is here. in action.

http://www.studyof911.com/thplay/
(please no comments about site.. Ok....)

And now here is the same code on windows.

http://deathgoth.no-ip.org:8080/test01/index1.php

They are both the same code yet on the Linux server it works fine and on the windows server it don't even work.

So this can be my 1st lesson in PHP.

1 off question, Do you guys talk about mysql also or no?

Posted: Sun Dec 10, 2006 5:02 pm
by feyd
Care to post the code itself?

Run the following in a new file on each server and tell us the results please.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>

Posted: Sun Dec 10, 2006 5:04 pm
by John Cartwright
If you look at the source code, you'll notice you'll see php code in there! This indicates that the PHP was not parsed, likely because you have short tags disabled.

Run the following in a new file on the server which the code does not work, and tell us the results please.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>
Now if short tags is disabled, then simply change <? ?> to <?php ?>
1 off question, Do you guys talk about mysql also or no?
Yes, we have a forum dedicated to it, the Databases forum.

Edit | beat by feyd :x

The Code

Posted: Sun Dec 10, 2006 5:15 pm
by ThichHeaded
The code is in 2 parts.

The main part is here.

Code: Select all

<?

define("OFFSET", 0);


define("YSECS", 365*24*60*60);
define("DSECS", 24*60*60);
define("HSECS", 60*60);
define("MSECS", 60);

function countdown($detail, $year, $month = 1, $day = 1, $hour = 0, $minute = 0, $second = 0) {
	$years = $days = $hours = $minutes = $seconds = 0;
	$now = mktime() + OFFSET*60*60;	
	$then = mktime($hour, $minute, $second, $month, $day, $year);	
	$cdown = abs($then - $now);
	
	if ($detail == 1) $years = round($cdown/YSECS);
	else $years = floor($cdown/YSECS);
	$cdown %= YSECS;
	if ($detail == 2) $days = round($cdown/DSECS);
	else $days = floor($cdown/DSECS);
	$cdown %= DSECS;
	if ($detail == 3) $hours = round($cdown/HSECS);
	else $hours = floor($cdown/HSECS);
	$cdown %= HSECS;
	if ($detail == 4) $minutes = round($cdown/MSECS);
	else $minutes = floor($cdown/MSECS);
	$cdown %= MSECS;
	$seconds = $cdown;
	
	$tnums = array($years, $days, $hours, $minutes, $seconds);
	$ttext = array("year", "day", "hour", "minute", "second");
	
	$shown = 0;
	
	for ($i=0;$i<$detail;$i++) {
		if ($tnums[$i]) {
			echo "$tnums[$i] $ttext[$i]";
			$shown++;
			if ($tnums[$i] != 1) echo "s";
			$count = 0;
			for ($j=$i+1;$j<$detail;$j++) {
				if ($tnums[$j]) $count++;
			}
			switch($count) {
				case 0: break 2;
				case 1: if ($shown>1) echo ","; echo " and "; break;
				default: echo ", "; break;
			}
		}
	}
	if ($now > $then) echo " ago";
	if ($now == $then) echo "now";
}
?>
You are right, the shorthand <? blabla ?> is on..

The page you are looking at above.

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
</HEAD>

<BODY>
<? include("cdown.php"); ?>
<CENTER>
<H2><P><B>Countdown to Site Release Date:</B><BR>
<? countdown(6, 2006,12,01,00,00,00); ?>
</p>
<P><B>The 1st ever Studyof911 Rally On 9/11/07 in New York City will be in:</B><BR>
<? countdown(6, 2007,9,11,09,30,00); ?></H2>
</p>
<P> <B>Halloween will be in:</B><BR>
<? countdown(3, 2006,10,31,0,1); ?>
</P>
<P><B>Thanksgiving will be in:</B><BR>
<? countdown(5, 2006,11,27,17,00,30); ?>
</p>
<P><B>DeathGoth's B-Day will be in:</B><BR>
<? countdown(5, 2006,12,12,20,45,01); ?>
</p>
<P><B>DeathGoth was born:</B><BR>
<? countdown(6, 1973,12,12,09,00,00); ?>
</p>
<P><B>Things on 9/11 that changed.:</B><BR>
<? countdown(5, 2001,9,11,8,42,00); ?>
</p>
</CENTER>
<BR>

</BODY>
</HTML>
Altho I have fixed the code to run regular and now it gives an error shown here.

http://deathgoth.no-ip.org:8080/test01/index11.php

I am just doing this so I can learn why there is/isn't errors from one OS to another.
I hope you guys don't mind..

I forgot Feyd and Jcart
http://deathgoth.no-ip.org:8080/test01/test02.php

Posted: Sun Dec 10, 2006 5:19 pm
by nickvd
Jcart wrote:If you look at the source code, you'll notice you'll see php code in there! This indicates that the PHP was not parsed, likely because you have short tags disabled.

Now if short tags is disabled, then simply change <? ?> to <?php ?>

Posted: Sun Dec 10, 2006 5:20 pm
by feyd
Jcart's guess was correct, short tags are off, as they should be. You will need to convert all "<?" to "<?php"

Converted?

Posted: Sun Dec 10, 2006 5:31 pm
by ThichHeaded
I have converted the tags as stated in earlier post..

Here is the fix.

http://www.studyof911.com/thplay/php/index11.php
Linux

http://deathgoth.no-ip.org:8080/test01/index11.php
Windows.

The error is coming from the windows server yet again.. I have added both php scripts that you guys gave me to both servers.. Here is what they say.

its saying this..
1) echo ","; echo " and "; break; default: echo ", "; break; } } } if ($now > $then) echo " ago"; if ($now == $then) echo "now"; } ?>

Countdown to Site Release Date:

Fatal error: Call to undefined function countdown() in D:\wamp\www\test01\index11.php on line 10
And is fine on the linux server.

http://www.studyof911.com/thplay/php/osinfo.php
Linux

http://deathgoth.no-ip.org:8080/test01/osinfo.php
Windows
Future referance

Studyof is Linux, DeathGoth.no-ip is windows server

Posted: Sun Dec 10, 2006 5:36 pm
by nickvd
BODY>
<?

define("O.....
You missed one...

Posted: Sun Dec 10, 2006 5:37 pm
by feyd
You have more short tags to fix. ;)

Posted: Sun Dec 10, 2006 5:43 pm
by ThichHeaded
Thanks, I was working in 2 diffrent area that had the same files. The file works now..

But haven you guys come across a code that would work on a linux box and not on a windows box??

I had one a long time ago that would not work on linux, but would work on windows..

I am not sure if I can reproduce that code because it was so long ago.. I am just wondering why it would do that.

Does it have to do with server contitions?? or something.

Posted: Sun Dec 10, 2006 5:47 pm
by feyd
The only times I've come close to a point where something had to run on Windows was when I was forced to write COM interactions, but properly coded most applications should be able to run on both with little problem that's individual to the environment.