Username: Save?
Password:
Home Forum Links Search Login Register*
    News: Welcome to the TechnoWorldInc! Community!
Recent Updates
[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[February 14, 2024, 02:00:39 PM]
Subscriptions
Get Latest Tech Updates For Free!
Resources
   Travelikers
   Funistan
   PrettyGalz
   Techlap
   FreeThemes
   Videsta
   Glamistan
   BachatMela
   GlamGalz
   Techzug
   Vidsage
   Funzug
   WorldHostInc
   Funfani
   FilmyMama
   Uploaded.Tech
   MegaPixelShop
   Netens
   Funotic
   FreeJobsInc
   FilesPark
Participate in the fastest growing Technical Encyclopedia! This website is 100% Free. Please register or login using the login box above if you have already registered. You will need to be logged in to reply, make new topics and to access all the areas. Registration is free! Click Here To Register.
+ Techno World Inc - The Best Technical Encyclopedia Online! » Forum » THE TECHNO CLUB [ TECHNOWORLDINC.COM ] » Programming Zone » PHP
 Create a counter with ad revenue options using PHP
Pages: [1]   Go Down
  Print  
Author Topic: Create a counter with ad revenue options using PHP  (Read 969 times)
Daniel Franklin
TWI Hero
**********


Karma: 3
Offline Offline

Posts: 16647


View Profile Email
Create a counter with ad revenue options using PHP
« Posted: September 26, 2007, 11:12:31 AM »


This was great for adult sites but not really suitable for mainstream sites due to the nature of the advertised images, well you can easily roll your own basic example which will serve the purpose of a counter and also offer some advertising revenue if anyone clicks on the links.

The system is split into 2 basic parts the first is the generation of an ad and the storing of the visitor count in a seperate file and the second which would be used by the webmaster is a system to display the stats.

Firsly create a file called paycounter.txt and put whatever the count you wish to display in it. Next create the script in part 1 and call it paycounter.php. This consists of various functions and features the first

<strong>Part 1 : The counter</strong>

<?php
$counter_file = ("paycounter.txt"); //counter file we are using
$visits = file($counter_file); //open file and read in data
$visits[0]++; //increment the visits variable by 1
$fp = fopen($counter_file , "w"); //open the file and store the new value
fputs($fp , "$visits[0]"); //write the new value to the text file
fclose($fp); //tidy up

//part 2 the banner display part
//some sample banners , use your own here these are just nonsense urls for the purpose of this example
$url = array("http://www.urlno1inhere.com",
"http://www.urlno1inhere.com",
"http://www.urlno1inhere.com",
"http://www.urlno1inhere.com");
//the urls for the images , replace these also
$imgsrc = array("http://www.urlno1inhere.com/image1.gif",
"http://www.urlno1inhere.com/image2.gif",
"http://www.urlno1inhere.com/image3.gif",
"http://www.urlno1inhere.com/image4.gif");
//this is alt tags for the links
$alt = array("about link 1 ",
"about link 2 ",
"about link 3 ",
"about link 4 ");

//generate a random number the number in $rn = (rand()%4); has to be changed
//depending on the amount of advertisers you have
srand((double)microtime() * 1000000); //random number generation
$rn = (rand()%4);
//display the banner and link . This opens in a new window
echo "
";
echo ("<img src =$imgsrc[$rn] alt =$alt[$rn]>"); //displays image with url link and alt text opens in new window
echo "
";
echo ("paycounter example"); //text underneath the image
echo "
";
?>

<strong>Part 2 : Show stats</strong>

This is a small script that can be put on a page called paystats.php for example. This also could be shown on a seperate page only viewable by the admin

We basically open up the paycounter file that we used in the first script and read in the value in it, then we display this on the screen.

<?php
$counter_file1 = ("paycounter.txt"); //open the counter file
$visits1 = file($counter_file1);
$fp1 = fopen($counter_file , "r");
fclose($fp1); //close file handle
echo $visits1[0]; //display count on screen
?>

<strong>Usage</strong>

Upload all files to your website ensuring that the paycounter text file is the same folder as the php files.

To use the paycounter part this is the code you would use say on a page on your site

<?php include("paycounter.php") ?>

For the stats you would use the following code

<?php include("paystats.php") ?>

Example

An example can be found on the following site address, paste into your favourite browser or you can use Internet Explorer. http://www.beginnersphp.co.uk/statspay.php

<strong>Improvements</strong>

Here are some improvements that could be made for all of the people with additional programming skills

MySQL backend for storing of stats and also for displaying of advertisements.
Use cookies to only register one visit per person in an certain period of time, say one per day.
Multiple pages with stats.
Articles Source - Free Articles

Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Copyright © 2006-2023 TechnoWorldInc.com. All Rights Reserved. Privacy Policy | Disclaimer
Page created in 0.118 seconds with 24 queries.