Important alert: (current site time 7/15/2013 11:26:18 AM EDT)
 

VB icon

CodeLib

Email
Submitted on: 12/22/2000 9:27:10 PM
By: Dennis Wrenn  
Level: Beginner
User Rating: By 10 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 18387
author picture
(About the author)
 
     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!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// 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
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=243&lngWId=8//for details.//**************************************

<?
//#############################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 4 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
12/13/2004 3:53:20 PM

Hi there, I must congratulate you for this nice piece of code I would do it myself.:) anyways I have a question if you can help plese let me know. 5 stars from me.
(If this comment was disrespectful, please report it.)

 
4/19/2005 10:38:46 PMnation-x

It's alright... not bad for a beginner... but would be better if it were modular like http://www.phpadultscripts.info
(If this comment was disrespectful, please report it.)

 
4/19/2005 10:52:08 PMnation-x

Here is an example...

Each section of the site is a file by itself that I include (using include('file.php');) header, nav, right links, footer and banners... I include them all in index.php... this way I only have to edit that one section and re-up anytime I need to change the site... then... all links on the site are as follows (index.php?target=content.php).
(If this comment was disrespectful, please report it.)

 
4/19/2005 10:52:21 PMnation-x

These are all of the main content pages that are loaded in the middle of the page. So... essentially... my site is only made of 1 page (index.php)... this is the code I use:

If I want to prevent surfers from loading the target pages I just add:

at the top of each target page (target.php being the content page name).
(If this comment was disrespectful, please report it.)

 
4/19/2005 10:57:35 PMnation-x

oops... I missed a quote after target.php... should be:

if
(!$_SERVER[PHP_SELF] == "target.php")
{
(If this comment was disrespectful, please report it.)

 
4/19/2005 10:58:20 PMnation-x

sorry... I was bored and wanted to help... =)
(If this comment was disrespectful, please report it.)

 
4/20/2006 1:56:53 AMYoury De Winter

Dear Dennis,
as i was looking trough your code i noticed a small remark to be made...
As i wrote an own system which logs the access to the page in a file, i noticed that some ISP's uses Forwarded IP's, which are partial spoofed.
PHP has a function to see if the IP is forwarded or not, and gives you the oportunity to get the real IP address of the visitor.
Anyway, here is the function i have used:
$ip = getenv("HTTP_X_FORWARDED_FOR");
if (empty($ip)) {
$ip = getenv("REMOTE_ADDR");
}
(If this comment was disrespectful, please report it.)

 

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.