You are here: code checking « All PHP « IT news, forums, messages
code checking

Posted by Moosus Gracius on 11/08/06 10:49

G'day all,

I am only new to php and do most of my codeing with a book in one
hand.

I have written a small script I wish to use as an include in the
footer of a site I am designing.

Whilst the code is functioning at the moment I was hoping I could get
some input from you as to making it a little more "clean" for want of
a better word.

Obviously there is some comments to pull. But I would like to hear if
there are ways I can make it neater / faster / smaller

Cheers
moosus




************************CODE***********************************
<?php
//Count & IP file name creation
if (isset($vid)){
$filecount =
$_SERVER['DOCUMENT_ROOT'].$vid."/counter/_count.txt";
$fileip = $_SERVER['DOCUMENT_ROOT'].$vid."/counter/_ip.txt";
} else {
$filecount =
$_SERVER['DOCUMENT_ROOT']."/counter".$_SERVER['PHP_SELF']."_count.txt";
$fileip =
$_SERVER['DOCUMENT_ROOT']."/counter".$_SERVER['PHP_SELF']."_ip.txt";
}
// Count file Check
if (file_exists($filecount) && file_exists($fileip)){
} else {
touch($filecount);
touch($fileip);
echo '<p>Touching Count & IP files</p>'; // Error Checking
}

echo '<p>file count name = '.$filecount.'</p><p>file ip name =
'.$fileip.'</p>'; //Error checking

// Tracking & recording
$fcount = fopen($filecount , "rw" ) or die();
$count = (int) fgets($fcount, 100);
echo '<p>count = '.$count.'</p>'; //Error checking
$fip = fopen( $fileip , "rw" ) or die();
$lastIp = fgets($fip, 50 );

$count++;

echo '<p>count = '.$count.'</p>'; //Error checking
fclose($fcount);
fclose($fip);

$fcount = fopen($filecount , "w" ) or die();
$fip = fopen($fileip , "w" ) or die();
flock($fcount, LOCK_EX);
fwrite( $fcount, $count);
flock($fcount, LOCK_UN);
flock($fip, LOCK_EX);
fwrite( $fip, $HTTP_SERVER_VARS["REMOTE_ADDR"] );
flock($fip, LOCK_EX);

fclose($fcount);
fclose($fip);

echo $count ; //Output Number

?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация