Current location: Hot Scripts Forums » Programming Languages » PHP » New Web Host, New Problem!

New Web Host, New Problem!

Reply
  #1  
Old 09-29-03, 11:08 AM
justchat justchat is offline
New Member
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
New Web Host, New Problem!

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 "&nbsp;</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\">&nbsp;</TD>\n";
echo "<TD align=left colspan=6 bgcolor=\"$color2\">\n";
echo "Password : <INPUT type=password name=mypass size=12>\n";
echo "&nbsp;<INPUT type=submit name=sub_action value=\"Reset\">\n";
echo "&nbsp;<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>&nbsp;</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 &copy;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
Reply With Quote
  #2  
Old 09-29-03, 12:22 PM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
http://www.justchat.co.uk/count/odtrackadmin.php3
I am prompted to download the script rather than view the rendered page!
Rename the page to .php instead of .php3 and see if that cures the problem.
Reply With Quote
  #3  
Old 09-29-03, 03:39 PM
justchat justchat is offline
New Member
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hi

Yup that worked, seems like going back in time with such an older version of php!

Thanks!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
random link problem doogi PHP 18 03-04-09 02:00 AM
file download problem ukyankee Perl 6 10-04-03 11:39 PM
jpGraph axis labeling problem Squeezer PHP 2 08-20-03 08:53 AM
Problem with CDONTS javadude2003 ASP 23 08-08-03 12:09 AM


All times are GMT -5. The time now is 10:47 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)