Page 1 of 1
Web Page not displaying correct variables
Posted: Thu Feb 16, 2006 5:22 am
by paulmac1966
I have written a php page which includes a hit counter.
If i run the page in a Linux shell (/usr/bin/php index.php) it outputs the format i would expect
but when i load the page through IE it does not show the same code.
ie
I have a variable which is read from a text file which increments by 1 every time the page is loaded, which
then displays the number on the web page, if i run the page in a shell i get the correct variable
BUT
when i load the page in IE it cant find the variable. WHY dont i get the same answer ?
Is there any way i can debug this, i have put loads of print statements in but this does not help as when i run it in a shell
i get the expected results
BUT when i load the page in IE i get different results.
This is very confusing.
Thanks in advance
Posted: Thu Feb 16, 2006 7:20 am
by Jenk
You can start by posting your code here so we can see exactly what is going on

Posted: Thu Feb 16, 2006 7:38 am
by paulmac1966
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Code: Select all
#!/usr/local/bin/php -q
<html>
<head>
<title>PHP Index Page</title>
</head>
<body>
<font color="#0000FF">
<? print "<p><h1 align=center>Casi Rusco FTP Web Site</h1></p>"; ?>
<hr>
<form action="action.php" method="post">
<p>Enter User Name: <input type="text" name="geusername"/></p>
<p>Enter Password  : <input type="password" name="gepasswd"/></p>
<p><input type="submit" value="Submit"/></p>
<?
####################
# Web Page Counter #
####################
function GetDigit ($Digit) {
switch ($Digit) {
case 0:
print "<img src='Digits/0.gif'>";
break;
case 1:
print "<img src='Digits/1.gif'>";
break;
case 2:
print "<img src='Digits/2.gif'>";
break;
case 3:
print "<img src='Digits/3.gif'>";
break;
case 4:
print "<img src='Digits/4.gif'>";
break;
case 5:
print "<img src='Digits/5.gif'>";
break;
case 6:
print "<img src='Digits/6.gif'>";
break;
case 7:
print "<img src='Digits/7.gif'>";
break;
case 8:
print "<img src='Digits/8.gif'>";
break;
case 9:
print "<img src='Digits/9.gif'>";
break;
default:
print "<img src='Digits/0.gif'>";
break;
}#end of switch
}#end of function
$count=`cat /tmp/webcount.txt`;# Works
print "Webcount is $count";#debug line
#$mycount=substr($count,0,6);
$count = $count + 1;
system("echo $count > /tmp/webcount.txt");
$No_digits=`cat /tmp/webcount.txt|wc -c`;
$No_digits = $No_digits - 1 ;#Keeps adding extra char (could be newline)
for ($D=1;$D<=$No_digits;$D++)# same as for I = 1 to 4
{
$Digit=`cat /tmp/webcount.txt|cut -c${D}`;#Get 1st char, 2nd char .... 4th
GetDigit($Digit);
}
?>
</form>
</body>
</html>
I did not post the code as i believe that there is nothing wrong with it, in fact i have installed the code on a local web server in our office and connected to it with IE and it works fine, its when i upload it to our external web server that i get different results ?
Thanks
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Thu Feb 16, 2006 7:49 am
by Jenk
eep! Use PHP tags please!
Anyway, there is something wrong as you are not achieving the results you want, and 99% of the time this means the code is 'wrong'
The error may be with the use of shell execing like you have done with this line:
I'm not sure if using PHP in non-command line reference will allow that to run, so try:
Code: Select all
$count = shell_exec('cat /tmp/webcount.txt');
instead and see what it returns.

According to the manual these are both indentical to one another (backticks to shell_exec) but you never know.
Posted: Thu Feb 16, 2006 10:32 am
by paulmac1966
I tried changing the system command to shell_exec, it makes no difference.
But if i view the source of the web page on the problem server i get the following
Code: Select all
<html>
<head>
<title>CASI-RUSCO UK FTP SITE</title>
<META NAME="description" CONTENT="">
<META NAME="keywords" CONTENT="Casi Rusco Casi-Rusco GE Security">
<META NAME="revisit-after" content="5 days">
</head>
<frameset rows="100%,*" framespacing="0" border="0" frameborder="0">
<noframes>
<body bgcolor="100" text="250">
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
<frame name="main" src="http://casi-rusco.serveftp.net" scrolling="auto">
</frameset>
</html>
if i view the source of the other working test server, i get the following code
Code: Select all
#!/usr/local/bin/php -q
<html>
<head>
<title>PHP Index Page</title>
</head>
<body>
<font color="#0000FF">
<p><h1 align=center>Casi Rusco FTP Web Site</h1></p><hr>
<form action="action.php" method="post">
<p>Enter User Name: <input type="text" name="geusername"/></p>
<p>Enter Password  : <input type="password" name="gepasswd"/></p>
<p><input type="submit" value="Submit"/></p>
Webcount is 10096
<img src='Digits/1.gif'><img src='Digits/0.gif'><img src='Digits/0.gif'><img src='Digits/9.gif'><img src='Digits/7.gif'></form>
</body>
</html>
why do i get such different results on two web servers which are built the same (i built them myself from o/s upwards)
the problem one seems to be complaining about frames, i have not used frames ?
p.s. sorry about the php / code tags, i did not know.
Posted: Thu Feb 16, 2006 11:01 am
by RobertGonzalez
It looks like your server is reading two different files. Do you have files that are named the same with different extensions (ie, default.htm, default.html, default.php)? Also, have you cleared your browsers cache to make sure you have the freshest page load?
cracked it
Posted: Fri Feb 17, 2006 8:30 am
by paulmac1966
I moved the text files i have been using from /tmp to /var/www/htm (ie the web root dir) and everything worked ok.
When i was testing the code in a shell and executing the php code i was logged in as root, so i did not have any
problems accessing directories higher up the tree.
It is basically a permissions problem on the unix directory system, due to using chroot on the web server.
Thanks to everyone who tried to help.