Web Programming  Home Web Programming PHP Simple Counter & Redirecting & Browser Type
rss

Simple Counter & Redirecting & Browser Type

Author: Andy More by this author


Simple Counter

This is a really 2 file way of making a unique hit counter.

If you make a new file called counter.txt and just type the number 1 on the first line.

In a new file, paste the script

<?
$file = "counter.txt";
$fp= @fopen($file,"r+"); //this opens the file
$myCounter = (int)fgets($fp,10000); //
++$myCounter; //
rewind($fp);
fwrite($fp,$myCounter); //this will write the value
fclose($fp);
echo $myCounter; //this shows the value
?>

And save it as counter.php

Then put in the script where you would like the counter to go!

<?
include("counter.php");
?>

Make sure these are in the same folder on your FTP, and chmod the file counter.txt to 777.

Redirecting

Simple tutorial that will redirect your user to any page:

Just insert this script where you would like it to show in your .php file:

<?php
header("Location: http://new.url/goes/here");
?>

Browser Type

Show your browser: just insert this script where you would like it to show in your .php file:

<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>


Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

Add comments to "Simple Counter & Redirecting & Browser Type"