How to write a module displaying banners?

0 like 0 dislike
2 views
For CMS you need to write a module displaying banners.
Tell me what the article about the principles of work like that? Protection against cheating, the counting of impressions and clicks.
Any ideas to rewrite some existing module from another CMS
by | 2 views

5 Answers

0 like 0 dislike
Put OpenX, CMS will write only the module, insert the zones in the right places.
by
0 like 0 dislike
refuse mysql in favor of redis will be able to consider statistics in real time, unless you expected million load
by
0 like 0 dislike
About protecting against cheating I do not know, and the rest.
For example:
in the DB table of banners
Columns: id, img, url, show, click (the value no need to explain I hope)
In the cms write something like:
\r
$banner=mysql_fetch_array(mysql_query("SELECT img,id FROM banners ORDER BY RAND() LIMIT 1 ")); mysql_query("UPDATE banners SET show=show+1 WHERE id='$banner[id]'"); $banner="
Баннер";
\r
In banner.php by analogy.
1)Filtered $_GET[id] to protect against injection.
2)Check on the cookies or in the session, clicked whether the companion banner before. If not, add one in the box click. Write a cookie or in the session, that at this banner I've clicked.
3)Redirectin friend url from the database.
\r
Like this. If somewhere in the code was wrong, do not swear, it is too late.
by
0 like 0 dislike
If you do not like RAND()
It is possible so:
\r
Create a table:
\r
CREATE TABLE `banners` ( `id` INT( 10 ) NOT NULL , `img` VARCHAR( 100 ) NOT NULL , `click` INT( 10 ) NOT NULL , `show` INT( 10 ) NOT NULL , `url` VARCHAR( 100 ) NOT NULL , `alt` VARCHAR( 100 ) NOT NULL , UNIQUE ( `id` ) ) 

\r
banner.php (I must includet in the main code):
\r
<?php\r$default_url='http://habrahabr.ru'; //Сюда перенаправляем по дефолту\r\rfunction generate_banner(){  //Генерирует код баннера\r$banner=mysql_fetch_array(mysql_query("SELECT id, img, alt FROM banners ORDER BY show ASC LIMIT 1"));\rmysql_query("UPDATE banners SET show=show+1 WHERE id='$banner[id]'");\r$banner="<a href='banner.php?go=1'>
$banner[alt]"; return $banner; } banner_go function($id){ //Redirect + test click in the session global $default_url; if(preg_match('[^0-9]',$id)){ $banner=mysql_query("SELECT url FROM banners WHERE id='$$id'"); if(mysql_num_rows($banner)>0){ $banner=mysql_fetch_array($banner); $default_url=$banner[url]; if($_SESSION[banners][$id][click]!=true){ $_SESSION[banners][$id][click]=true; mysql_query("UPDATE banners SET click=click+1 WHERE id='$banner[id]'"); } } } header("Location: $default_url"); } if(isset($_GET[go])){ banner_go($_GET[go]); } ?>
\r
Check for click on a specific banner per session. Banners are displayed in turn.
by
0 like 0 dislike
practice shows that the pitfalls and "the list" managers-advertisers in bannerki the roof.
and all sorts of statistics of impressions and advertising strategy and priorities shows, and other, other.
\r
if you have no idea how to approach this — vote for OpenX, see what's inside.
and then decide — whether to write their own.
\r
well, the banner network has not been canceled.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
0 like 0 dislike
3 answers
0 like 0 dislike
7 answers
110,608 questions
257,186 answers
0 comments
28,758 users