Hi
I have since moved web hosts and am having trouble with my php pages since the move.
I have already worked out and had to change the command:
<? print $_SERVER ["REMOTE_ADDR"] ?>
to
<? print ("$REMOTE_ADDR"); ?>
As the first wouldnt work on the new server. My host says it uses PHP version 4.0.6 , not sure what the previous host was using but I had no problems before.
I am also using odtrack to count the number of times certain links are used and I cannot for the life of me work out why this isnt working and cant correct it myself. When I type in the URL:
http://www.justchat.co.uk/count/odtrackadmin.php3
I am prompted to download the script rather than view the rendered page!
The script is:
<?php
/* Admin password */
$passwd = "xxxxxxx";
/*** DO NOT EDIT BELOW THIS LINE ***/
$logfile = "log";
$tmpdir = "tmp/";
$version = "v1.1";
$color1 = "#006699";
$color2 = "#cccccc";
$color3 = "#ffffff";
$fieldname = array('Link name','Hits','First access','Last access','Accessed by','Referer');
$lockfile = $tmpdir . $logfile . ".lock";
function SortEntry($array) {
for($i=0; $i<count($array); $i++) {
list($title[$i],$url[$i],$hit[$i],$first[$i],$last[$i],$host[$i],$refer[$i]) = split("\|\|",$array[$i]);
$temp[$i] = (int)$hit[$i];
}
arsort($temp);
$j = 0;
reset($temp);
while(list($key,$val) = each($temp)) {
$id[$j] = $key;
$j++;
}
for($i=0; $i<count($id); $i++) {
$sorted[$i] = $array[$id[$i]];
}
return $sorted;
} /* end of SortEntry */
function ListEntry() {
global $PHP_SELF,$logfile,$color1,$color2,$color3,$fieldn ame;
$error1 = "Fail to open <B>'$logfile'</B> file";
clearstatcache();
if(!file_exists($logfile)) {
PrintMsg("Error : Log file is not exist");
return 0;
}
elseif(filesize($logfile) == 0) {
PrintMsg("Error : Log file is empty");
return 0;
}
elseif(!is_readable($logfile)) {
PrintMsg("Error : Could not access log file");
return 0;
}
else {
$fp2 = @file($logfile) or die($error1);
$fp = SortEntry($fp2);
echo "<FORM action=\"$PHP_SELF?action=modify\" method=POST>\n";
echo "<TABLE border=0 cellspacing=3 cellpadding=5>\n";
echo "<TR>\n";
echo "<TH bgcolor=\"$color1\" align=center colspan=2>";
echo "<FONT color=\"$color3\">$fieldname[0]</FONT></TH>\n";
for($i=1; $i<count($fieldname); $i++) {
echo "<TH bgcolor=\"$color1\" align=center>";
echo "<FONT color=\"$color3\">$fieldname[$i]</FONT></TH>\n";
}
echo "</TR>\n";
$num = 7; /* number of logfile fields */
for($i=0; $i<count($fp); $i++) {
$entry = split("\|\|",$fp[$i]);
echo "<TR>\n";
echo "<TD align=center bgcolor=\"$color2\">";
echo "<INPUT type=checkbox name=\"id[]\" value=\"$entry[1]\"></TD>\n";
echo "<TD align=left bgcolor=\"$color2\">";
echo "<A href=\"$entry[1]\">$entry[0]</A></TD>\n";
for($j=2; $j<$num; $j++) {
echo "<TD align=center bgcolor=\"$color2\">";
if(trim($entry[$j]) == "") echo " </TD>\n";
else {
$entry[$j] = chop($entry[$j]);
if($j == 6) {
if(strlen($entry[$j]) > 30) $text = substr($entry[$j],0,30) . "...";
else $text = $entry[$j];
if(eregi("^$entry[$j]$","NaN")) echo "Direct typing/ bookmark</TD>\n";
elseif($entry[$j] == "-") echo "$text</TD>\n";
else echo "<A href=\"$entry[$j]\">$text</A></TD>\n";
}
else echo $entry[$j] . "</TD>\n";
}
}
echo "</TR>\n";
}
echo "<TR>\n";
echo "<TD align=center bgcolor=\"$color2\"> </TD>\n";
echo "<TD align=left colspan=6 bgcolor=\"$color2\">\n";
echo "Password : <INPUT type=password name=mypass size=12>\n";
echo " <INPUT type=submit name=sub_action value=\"Reset\">\n";
echo " <INPUT type=submit name=sub_action value=\"Delete\"></TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</FORM>\n\n";
}
} /* end of ListEntry */
function ResetEntry($id) {
global $PHP_SELF,$logfile,$color1,$color2,$fieldname;
global $tmpdir,$lockfile;
$error1 = "Fail to open <B>'$logfile'</B> file";
clearstatcache();
if(filesize($logfile) == 0) {
PrintMsg("Log file is empty");
return 0;
}
elseif(!is_readable($logfile) && !is_writeable($logfile)) {
PrintMsg("Could not access log file");
return 0;
}
else {
$lockcount = 0;
$success = 0;
while($lockcount < 5) {
if(!file_exists($lockfile)) {
$plock = @fopen($lockfile,'w') or die("Fail to obtain lockfile");
fclose($plock);
copy($logfile,$tmpdir.$logfile.".bak"); /* create backup */
$fp = @file($logfile) or die($error1);
$k = 0;
for($i=0; $i<count($fp); $i++) {
$entry = split("\|\|",$fp[$i]);
$match = 0;
for($j=0; $j<count($id); $j++) {
if($entry[1] == $id[$j]) {
$match = 1;
break;
}
}
if($match == 1)
$new[$k] = "$entry[0]||$entry[1]||0||-||-||-||-";
else
$new[$k] = chop($fp[$i]);
$k++;
}
$string = implode("\n",$new);
$pointer = @fopen($logfile,"w") or die($error1);
fwrite($pointer,$string);
fclose($pointer);
$success = 1;
unlink($lockfile); /* release lock */
break;
} /* end if lockfile */
else {
$lockcount++;
if(time() - filectime($lockfile) > 300) { /* something wrong */
unlink($lockfile);
$lockcount = 0;
}
sleep(1);
clearstatcache();
}
} /* end while */
if($success == 0) {
PrintMsg("Failed to reset entry. The log file might be in used. Please try again.");
return 0;
}
}
} /* end of ResetEntry */
function DeleteEntry($id) {
global $PHP_SELF,$logfile,$color1,$color2,$fieldname;
global $tmpdir,$lockfile;
$error1 = "Fail to open <B>'$logfile'</B> file";
clearstatcache();
if(filesize($logfile) == 0) {
PrintMsg("Log file is empty");
return 0;
}
elseif(!is_readable($logfile) && !is_writeable($logfile)) {
PrintMsg("Could not access log file");
return 0;
}
else {
$lockcount = 0;
$success = 0;
while($lockcount < 5) {
if(!file_exists($lockfile)) {
$plock = @fopen($lockfile,'w') or die("Fail to obtain lock file");
fclose($plock);
copy($logfile,$tmpdir.$logfile.".bak"); /* create backup */
$fp = @file($logfile) or die($error1);
$k = 0;
for($i=0; $i<count($fp); $i++) {
$entry = split("\|\|",$fp[$i]);
$match = 0;
for($j=0; $j<count($id); $j++) {
if($entry[1] == $id[$j]) {
$match = 1;
break;
}
}
if($match == 0) {
$new[$k] = chop($fp[$i]);
$k++;
}
}
if(count($new) > 1)
$string = implode("\n",$new);
elseif(count($new) == 1)
$string = $new[0];
else
$string = "";
$pointer = fopen($logfile,"w") or die($error1);
fwrite($pointer,$string);
fclose($pointer);
$success = 1;
unlink($lockfile); /* release lock */
break;
} /* end if lockfile */
else {
$lockcount++;
if(time() - filectime($lockfile) > 300) { /* something wrong */
unlink($lockfile);
$lockcount = 0;
}
sleep(1);
clearstatcache();
}
} /* end while */
if($success == 0) {
PrintMsg("Failed to delete entry. The log file might be in used. Please try again.");
return 0;
}
} /* end else */
} /* end of DeleteEntry */
function AddEntry($title,$url) {
global $PHP_SELF,$logfile;
global $tmpdir,$lockfile;
$error1 = "Fail to open <B>'$logfile'</B> file";
if(!is_writeable($logfile) || !file_exists($logfile)) {
PrintMsg("Error : unable to open <B>'$logfile'</B>");
return 0;
}
else {
if((trim($title) == "")||(trim($url) == "")) {
PrintMsg("Error : please fill all fields");
return 0;
}
clearstatcache();
$lockcount = 0;
$success = 0;
while($lockcount < 5) {
if(!file_exists($lockfile)) { /* file is not locked */
$plock = @fopen($lockfile,'w') or die("Fail to obtain lock file");
fclose($plock);
if(filesize($logfile) != 0) {
copy($logfile,$tmpdir.$logfile.".bak"); /* create backup */
$fp = @file($logfile) or die($error1);
for($i=0; $i<count($fp); $i++) {
$fp[$i] = chop($fp[$i]);
$entry = split("\|\|",$fp[$i]);
$chop_entry = eregi_replace("/$","",$entry[1]);
$chop_url = eregi_replace("/$","",$url);
if(eregi("^$chop_url$",$chop_entry)) {
PrintMsg("Entry is already exist : <A href=\"$entry[1]\">$entry[0]</A>");
unlink($lockfile);
return 0;
}
}
$fp[count($fp)] = "$title||$url||0||-||-||-||-";
$string = implode("\n",$fp);
}
else {
$string = "$title||$url||0||-||-||-||-";
}
$pointer = @fopen($logfile,"w") or die($error1);
fwrite($pointer,$string);
fclose($pointer);
$success = 1;
unlink($lockfile);
break;
}
else { /* file is locked */
$lockcount++;
if(time() - filectime($lockfile) > 300) { /* something wrong */
unlink($lockfile);
$lockcount = 0;
}
sleep(1);
clearstatcache();
} /* end lockfile */
} /* end while */
if($success == 0) {
PrintMsg("Failed to add entry. The log file might be in used. Please try again.");
return 0;
}
return 1;
}
} /* end of AddEntry */
/************************************************** ******************/
function frmAddEntry() {
global $PHP_SELF,$logfile,$color1,$color2,$color3,$fieldn ame;
echo "<FORM action=\"$PHP_SELF?action=add\" method=POST>\n";
echo "<TABLE border=0 cellspacing=0 cellpadding=5>\n";
echo "<TR><TD align=left valign=middle colspan=2 bgcolor=\"$color1\">\n";
echo " <FONT color=\"$color3\"><B>Add new link</B></FONT></TD>\n";
echo "</TR>\n";
echo "<TR><TD align=right valign=middle width=100>Title : </TD>\n";
echo " <TD align=left valign=top width=350>\n";
echo " <INPUT type=text name=title size=30></TD>\n";
echo "</TR>\n";
echo "<TR><TD align=right valign=middle width=100>URL : </TD>\n";
echo " <TD align=left valign=top width=350>\n";
echo " <INPUT type=text name=url size=30></TD>\n";
echo "</TR>\n";
echo "<TR><TD align=right valign=middle width=100>Password : </TD>\n";
echo " <TD align=left valign=top width=350>\n";
echo " <INPUT type=password name=mypass size=10></TD>\n";
echo "</TR>\n";
echo "<TR><TD align=right valign=top width=100> </TD>\n";
echo " <TD align=left valign=top width=350>\n";
echo " <INPUT type=submit value=\"Add\"></TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</FORM>\n";
} /* end of frmAddSection */
function CheckPass($passwd1,$passwd2) {
if($passwd1 == $passwd2) return 1;
else return 0;
} /* end of CheckPass */
function PrintMsg($msg) {
global $color2;
echo "<TABLE border=0 cellspacing=0 cellpadding=5>";
echo "<TR><TD width=460 align=left bgcolor=\"$color2\">";
echo $msg;
echo "</TD>\n</TR>\n</TABLE>\n<BR>";
} /* end of PrintMsg */
?>
<HTML>
<HEAD>
<TITLE> ODTrack Admin </TITLE>
<STYLE type=text/css>
<!--
BODY,TD,TH { font-family : arial,helvetica,verdana,sans-serif;
font-size : 10pt;
}
.TITLE { font-family : arial,helvetica,verdana,sans-serif;
font-size : 12pt;
font-weight : bold;
color : #006699;
}
.SMALL { font-family : arial,helvetica,verdana,sans-serif;
font-size : 8pt;
}
-->
</STYLE>
</HEAD>
<BODY bgcolor="#ffffff" text="#000000">
<CENTER>
<FONT class=title>ODTrack Admin</FONT><BR>
[ <A href="<? echo $PHP_SELF; ?>">Main</A> ]
[ <A href="<? echo $PHP_SELF; ?>">Refresh</A> ]<BR>
<BR><BR><BR>
<?
switch($action) {
case "add" : if(trim($mypass) == "") PrintMsg("Error : password required");
elseif(!CheckPass($mypass,$passwd)) PrintMsg("Error : invalid password");
else AddEntry($title,$url);
clearstatcache();
if(filesize($logfile) != 0) ListEntry();
else PrintMsg("You have <B>0</B> entry");
frmAddEntry();
break;
case "modify" : if(trim($mypass) == "") PrintMsg("Error : password required");
elseif(!CheckPass($mypass,$passwd)) PrintMsg("Error : invalid password");
elseif(count($id) == 0) PrintMsg("Please select at least 1 link");
elseif($sub_action == "Reset") ResetEntry($id);
elseif($sub_action == "Delete") DeleteEntry($id);
clearstatcache();
if(filesize($logfile) != 0) ListEntry();
else PrintMsg("You have <B>0</B> entry");
frmAddEntry();
break;
default : clearstatcache();
if(filesize($logfile) != 0) ListEntry();
else PrintMsg("You have <B>0</B> entry");
frmAddEntry();
}
?>
<BR>
<HR width=700>
<FONT class=small>
Powered by ODTrack <? echo $version; ?><BR>
Copyright ©2000 by <A href="mailto:rini@oodie.com">Rini Setiadarma</A>.
All rights reserved.
</FONT>
</CENTER>
</BODY>
</HTML>
Any ideas would be gratefully received, along with any info as to why I am only now having problems!!
Thanks in advance
Martin