Steven.
05-06-2005, 02:26 AM
Hello!
this is a Simple guide and list of PHP snippets, Sorry if it has been Posted Before.
Hit Counter:
Create a file and name it count.dat, CHMOD it to 777
<?php
$counterfile = "count.dat";
if(!($fp = fopen($counterfile,"r"))) die ("cannot open counter file");
$count = (int) fread($fp, 20);
fclose($fp);
Display users IP address:
<?php echo $_SERVER['REMOTE_ADDR']; ?>
Lines in a file:
<?php
$filename = "yourfile.txt";
$lines = file($filename);
$count = count($lines);
echo("There are $count lines in the file.");
?>
Show referer:
<?php echo $_SERVER['HTTP_REFERER']; ?>
Server path:
<?php echo getcwd(); ?>
IP Logger:
Create and upload a file called "ips.txt" CHMOD the file to 777
<?php
$v_ip = $REMOTE_ADDR;
$v_date = date("l d F H:i:s");
$fp = fopen("ips.txt", "a");
fputs($fp, "IP: $v_ip - DATE: $v_date\n\n");
fclose($fp);
?>
24hr Clock:
<?php echo date("H:i:s"); ?>
Display page load time:
<?
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();
for ($i=0; $i <1000; $i++){
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
$time = round($time,4);
echo "This page loaded in $time seconds.";
?>
24Hr clock and Day:
<?php echo date("l g:ia"); ?>
Display users browser info:
<?php echo $HTTP_USER_AGENT ?>
Full date and time:
<?php echo date("l d F Y"); ?>
Multi ban IP Address's:
<?php $ip = getenv('REMOTE_ADDR');
$ip1 = "xxx.xxx.xxx";
$ip2 = "xxx.xxx.xxx";
if($ip == $ip1 || $ip == $ip2)
{
echo"You are banned from this site.";
exit ();
}
?>
Page include:
<?php include "PAGEHERE.php"; ?>
I Hope this will help. Any Questions feel free to Post them here or PM Me.
Sorry again if this has already been done.
this is a Simple guide and list of PHP snippets, Sorry if it has been Posted Before.
Hit Counter:
Create a file and name it count.dat, CHMOD it to 777
<?php
$counterfile = "count.dat";
if(!($fp = fopen($counterfile,"r"))) die ("cannot open counter file");
$count = (int) fread($fp, 20);
fclose($fp);
Display users IP address:
<?php echo $_SERVER['REMOTE_ADDR']; ?>
Lines in a file:
<?php
$filename = "yourfile.txt";
$lines = file($filename);
$count = count($lines);
echo("There are $count lines in the file.");
?>
Show referer:
<?php echo $_SERVER['HTTP_REFERER']; ?>
Server path:
<?php echo getcwd(); ?>
IP Logger:
Create and upload a file called "ips.txt" CHMOD the file to 777
<?php
$v_ip = $REMOTE_ADDR;
$v_date = date("l d F H:i:s");
$fp = fopen("ips.txt", "a");
fputs($fp, "IP: $v_ip - DATE: $v_date\n\n");
fclose($fp);
?>
24hr Clock:
<?php echo date("H:i:s"); ?>
Display page load time:
<?
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();
for ($i=0; $i <1000; $i++){
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
$time = round($time,4);
echo "This page loaded in $time seconds.";
?>
24Hr clock and Day:
<?php echo date("l g:ia"); ?>
Display users browser info:
<?php echo $HTTP_USER_AGENT ?>
Full date and time:
<?php echo date("l d F Y"); ?>
Multi ban IP Address's:
<?php $ip = getenv('REMOTE_ADDR');
$ip1 = "xxx.xxx.xxx";
$ip2 = "xxx.xxx.xxx";
if($ip == $ip1 || $ip == $ip2)
{
echo"You are banned from this site.";
exit ();
}
?>
Page include:
<?php include "PAGEHERE.php"; ?>
I Hope this will help. Any Questions feel free to Post them here or PM Me.
Sorry again if this has already been done.