I built this recently for something , i thought i would share.
This is a simple script to display ads based on
keywords in your pages title . The script will
detect the pages title and display ads/banners from a list based on the keywords in the pages title. The idea being many sites have thousands of pages but the banners are template driven so they either have the same banner across the entire site in that spot or they randomly rotate banners based on no criteria.
Very usefull for things like tubesites,networks etc
make a folder called js on your server
http://yoursite.com/js/
save the following as "javascript.php" in the folder you just created
Code:
<?php
Header("content-type: application/x-javascript");
?>
var scriptfolder = "http://yoursite.com/js/";
var mdt = document.title;
var title = mdt.toLowerCase().replace(/^\s+|\s+$/g, "").replace(/[_|\s]+/g, "-").replace(/[^a-z0-9-]+/g, "").replace(/[-]+/g, "-").replace(/^-+|-+$/g, "");
sij = scriptfolder + title + ".js";
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= sij;
head.appendChild(script);
Save the following as ".htaccess" in the same folder
Code:
RewriteEngine on
RewriteRule ^(.*)\.js index.php?x=$1 [nc]
Save the following as "index.php" in the same folder
Code:
<?php
Header("content-type: application/x-javascript");
$x = $_GET['x'];
$x = str_replace("-"," ",$x);
$list = file_get_contents("list.txt");
$ali = explode("\n",$list);
$fli = explode("|",$ali[0]);
// default banner
$surl = $fli[1];
$simg = $fli[2];
// shuffle list
shuffle($ali);
foreach( $ali as $ky => $me){
$eme = explode("|",$me);
$keyword = $eme[0];
if (strlen(stristr($x,$keyword))>0) {
$surl = $eme[1];
$simg = $eme[2];
}
}
?>
surl = "<?php echo $surl; ?>";
simg = "<?php echo $simg; ?>";
document.getElementById('stbad').innerHTML = "<a href='" + surl + "' target='_blank'><img src='" + simg + "'></a>";
now save the following code as list.txt in same folder ( edit to your sponsors )
Code:
default|http://defaultsponsor|https://gfy.com/skins/gfy2007hdr/logo.gif
gay|http://sponsor.com/?x=myrefcode|http://sponsor.com/banner.jpg
twink|http://twink.com/?x=myrefcode|http://sponsor.com/banner.jpg
gfy|https://gfy.com|https://gfy.com/skins/gfy2007hdr/logo.gif
So in a nutshell the script will detect the current pages title, it will load "pages-title.js" the php will check your list.txt and see if any keywords you have in your list match keywords in the pages title, if so it will choose one to display.
The first banner is the default banner, you can use multiple banners/sponsors for the same keyword , it will randomly pick one.
to use just place the following code on your page where you want the banner to appear
( it will show up in the div )
Code:
<div id=stbad></div>
<script src=http://yoursite.com/js/javascript.php></script>