VB icon

CodeLib

Email
Submitted on: 1/1/2015 4:03:00 AM
By: Dennis Wrenn (from psc cd)  
Level: Beginner
User Rating: By 10 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 2246
 
     This is a group of functions I wrote so I didn't have to write things over and over in an HTML file..

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: CodeLib
// Description:This is a group of functions I wrote so I didn't have to write things over and over in an HTML file..
// By: Dennis Wrenn (from psc cd)
//**************************************

<?
//#############################COUNTER FUNCTIONS#############################\//create a directory called hits in your 
//main directory
function gethits($logpath) {
	$hits = 0;
	$logpath = "./hits/".$logpath.".hits";
	If (file_exists($logpath)) {
		$filenum = fopen($logpath,"r");
		if ($filenum > 0) {
			$filesize = filesize($logpath);
			$hits = fread($filenum,$filesize+1);
			fclose($filenum);
		}
	} else {
		$filenum = fopen($logpath,"w");
		fwrite($filenum,$hits);
		fclose($filenum);
	}
	return $hits;
}
function addhit($logpath) {
	$hits = 0;
	$logpath = "./hits/".$logpath.".hits";
	If (file_exists($logpath)) {
		$filenum = fopen($logpath,"r");
		if ($filenum > 0) {
			//Get the current file hit count
			$filesize = filesize($logpath);
			$hits = fread($filenum,$filesize);
			fclose($filenum);
			//Increment the hit counter
			$hits++;
			$filenum = fopen($logpath,"w");
			fwrite($filenum,$hits);
			fclose($filenum);
		}
	}else{
		$hits++;
		$filenum = fopen($logpath,"w");
		fwrite($filenum,$hits);
		fclose($filenum);
	}
	return;
}
//#############################IP FUNCTIONS#############################\//logs IP for forums and stuff like that
function logip($path) {
	global $REMOTE_ADDR;
	writetolog($path, "$REMOTE_ADDR*\n");
}
function parseips($ips) {
	return str_replace("*", "<BR>", $ips);
}
//#############################FILE FUNCTIONS#############################\//for logip functions, and others I will soon write
function writetolog($logfile, $texttowrite) {
	$filenum = fopen($logfile,"a");
	fwrite($filenum,$texttowrite);
	fclose($filenum);
}
function openfile($path) {
if(file_exists($path) == 0) {
return "";
}
else
{
$thefilesize = filesize($path);
$filenum = fopen($path,"r");
$filecontent = fread($filenum, $thefilesize+1);
fclose($filenum);
return $filecontent;
}
}
//#############################HEADER AND FOOTER#############################\//use like this:
//showheader("title","path");
function showheader($title, $path) {
	$link = ; //link color
	$alink = ; //active link color
	$vlink = ; //visited link color
	$bgcolor = ; // BG color
	$text = ; // textcolor
	addhit($path);
	echo "<HTML>\n";
	echo "<HEAD>\n";
	echo "<TITLE>$title</TITLE>\n";
	echo "<HEAD>\n";
	echo "<BODY BGCOLOR=$bgcolor TEXT=$text LINK=$link ALINK=$alink VLINK=$vlink>\n";
	echo "<FONT FACE=\"Arial\" SIZE=2>\n";
	showsidebar($title);
		
	echo "<BR>\n";
}
function showfooter($path) {
	echo "<P>\n";
	echo "<BR>\n";
	echo "<CENTER>";
	echo "<FONT COLOR=\"#0000FF\" SIZE=2>\n";
	echo "There have been <B>";
	echo gethits($path);
	echo "</B> visitors to this page since 12/19/2000 <BR>\n";
	echo "Copyright  2000 Your Name ";
	echo "All rights reserved <BR> \n";
	echo "</FONT>\n";
	echo "</TD>\n</TR>\n</TABLE>\n";
	echo "</CENTER>\n";
	echo "</FONT>\n";
	echo "</BODY>\n</HTML>";
}
function showsidebar($title) {
//look at screenshot, and change what you need.
	echo "<TABLE BORDER=3 BORDERCOLOR=\"#336699\" WIDTH=100% HEIGHT=100% CELLPADDING=\"20\" CELLSPACING=0>\n";
	echo "<TR>\n<TD WIDTH=15% BGCOLOR=\"#336699\" VALIGN=\"CENTER\" ALIGN=\"CENTER\"><IMG SRC=\"images/dw.gif\"></TD>";
	echo "<TD WIDTH=85% BGCOLOR=\"#336699\" VALIGN=\"CENTER\" ALIGN=\"CENTER\">";
	echo "<FONT COLOR=\"#FFFFFF\">\n";
	showtitle($title);
	echo "</FONT>\n";
	echo "<TR>\n<TD WIDTH=15% BGCOLOR=\"#336699\" VALIGN=\"TOP\" ALIGN=\"CENTER\">";
//create a file called sidebar.txt
//and put some links in there. It 
//must be in HTML format.EG:
//<A HREF="link1.htm">Link1</A><BR>
//<A HREF="link2.htm">link2</A><BR>
//etc
//be sure to leave a blank line at the top of the
//file.
	$file = openfile("sidebar.txt");
	echo "$file";
	echo "</TD>\n<TD WIDTH=85% VALIGN=\"TOP\" ALIGN=\"LEFT\">";
}
function showtitle($title) {
	echo "\n<H1><CENTER>$title</CENTER></H1>\n";
}
function showsubtitle($stitle,$size=2) {
	echo "<FONT COLOR=\"#0000FF\">\n<H$size><CENTER>$stitle</CENTER></H$size>\n</FONT>";
}
?>


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.