Home
Home Page
Web Bases with LWP
Transformation relative in absoljutye links
For the greater information read the full documentation on LWP:: UserAgent.
Accessing HTTPS URLs
Job with the text and graphic data in common in PHP and MySQL
Change of appearance of the counter in CNStats
Simple banner system phpFBS
How to protect a site from total uploading.
21 mistake of programmer PHP
API functions
Minuses of use API of functions
Generation of the image
The guest book step by step
The guest book on PHP/MySQL
PHP - Simple caching
Even about protection e-mail addresses on webs - pages
Language of web - statistics
Program extract of the bill in system WebMoney
Language of web - statistics
Links

 

Simple banner system phpFBS

For small projects if they initially are not focused on advertising, often there is a need{requirement} of a partner exchange of banners. Usually such happens few times in a month, and you decide what not bad to have near at hand the tool with which help it is possible to operate easily and simply banner places on pages of your site.



Introduction


For small projects if they initially are not focused on advertising, often there is a need{requirement} of a partner exchange of banners. Usually such happens few times in a month, and you decide what not bad to have near at hand the tool with which help it is possible to operate easily and simply banner places on pages of your site.


What in our case means <to operate banner places>? What it is necessary for us from banner system? We list necessary functions:


1. The centralized storage of banners and information on them.

2. Loading a banner on a site through the web - interface.

3. Installation of the directing link.

4. Addition of new recordings about banners.

5. Removal{Distance} of recordings about banners.

6. Viewing a code and testing of a banner.


All these functions are carried out simple, in my opinion, by banner system phpFBS (FoxWeb Banner System), written on language PHP with base MySQL for 4 hours.

The description of banner system


The system will consist of three PHP-scripts:


1. adm.php - the panel of administration of banners.

2. conf.php - connections to base and adjustments.

3. i.php - for two functions: show and transition of a banner.


Banners will be stored{kept} and be loaded into directories <b> by default a file - picture, that is. Naturally, rights should be established on it{her} chmod 777 for an opportunity of loadings.


ATTENTION! It is not recommended to use in names of scripts and directories a word banner or similar words, in that case the data, sent to the user automatically <obrezajutsja> proxies and fajrvolami. At testing banner system at my customer it also happened:)


Let's begin with simple - connection to DB MySQL. It carries out a script conf.php. Establish in him necessary registration given MySQL-connections. He is born separately because connection is necessary for <adminskoj> and for <vyvodnoj> parts. In a database we need only one table banners the following structure:



CREATE TABLE ` banners ` (

` banner_id ` tinyint (1) unsigned NOT NULL auto_increment,

` bannername ` varchar (50) default NULL,

` filename ` varchar (50) default NULL,

` url ` varchar (50) default NULL,

` comment ` varchar (50) default NULL,

PRIMARY KEY (` banner_id `)

) ENGINE=MyISAM;


At once I want to please supporters of a file way of storage of recordings - you are free to think out the functions, but from a DB this system has turned out extremely simple. And if the future it is required to you of 100 and more recordings - here certainly the DB undoubtedly wins.


conf.php



<? php

mysql_connect ("localhost", "db_user", "db_pass");

mysql_select_db ("db_name");

?>


Let's pass to a script of a conclusion and perenapravlenija. To him it is passed two parameters: action (action) and id (number{room} of a banner in the table). First of all the script is connected to base and carries out search about recording id to learn{find out} a way to a file of a banner and the link on which he conducts. Generally speaking, in both cases it is carried out perenapravlenie:


* i.php? action=redirect*id=1 - it is carried out perenapravlenie on the address of a banner specified in base in a field url. This habitual all action at a clique on a banner the mouse.

* i.php? id=1 - it is carried out perenapravlenie on the file of a banner specified in base in a field filename. Actually the banner is deduced in a window of a browser as though we have requested it{him} directly (but by means of readdressing from i.php). Well, in general you have understood:)


i.php



<? php

include "conf.php";

$query = " SELECT * FROM banners WHERE banner_id = $ id ";

$f = mysql_fetch_array (mysql_query ($query));

extract ($f);

if ($action == "redirect") header (" Location: ". $url);

elseif (! $action) header (" Location: http: // $HTTP_HOST/b / ". $ filename);

?>


Perenapravlenie standard function PHP header () carries out. Apparently from a code, anything complex{difficult}.


The most complex{difficult} part (in comparison with the others, but actually all is very simple) is a script of administration adm.php. brief structure of this file:


* include ("conf.php") - connection to a DB.

* function http ($str) - adds http:// if necessary. The user can enter URL a banner both with a prefix http://, and without him{it} and system it takes into account.

* function banners_table () - deduces the table of banners. Actually on the screen - contents of the table banners from a DB.

* function banner_code ($ banner _ id) - deduces a HTML-code of a banner to the user.

* function banner_show ($banner_id) - shows the test of a banner. He will be shown how will look on HTML-page of a site.

* Updating the data in base and zakachka a file by pressing the button of sending the form

if ($action == "write" ** $banner_id)

* Addition of new recording (it is strict after max numbers{rooms})

if ($action == "add" ** $comment)

* Removal{Distance} of recording with specified id

if ($action == "delete" ** $banner_id)

* Loading the data in the form from recording with specified id

if ($action == "read" ** $banner_id)

* Displays a HTML-code of a banner

if ($action == "code" ** $banner_id)


Let's say, you have added and have edited recordings, have loaded banners and what is farther? Now having clicked on the link <code> in a line corresponding to the necessary banner, you receive a HTML-code the image - link like:



<a href = "./i.php? action=redirect*id=1 "> <img src = "./i.php? id=1 " border = "0"/> </a>


Now you can place it a code in the necessary places of your HTML-pages and... To forget about them as now at change of a banner you will need to change only recording in the panel of administration.


The complete set of files is accessible here. In the same place the SQL-script for creation of the table banners and a demo of system is stored{kept}.


The described banner system is really used on a site http://58region.ru. It is necessary to note, what is it very simple banner system, and I have tried to make its{her} maximum "transparent" for the subsequent escalating and perfection.