Forum Moderators: martinibuster
I simply place the AdSense code in a text file and call it "adsense.txt".
Then I addded this code to my pages -
<!--#include virtual="adsense.txt"-->
Just make sure you have this line in your .htaccess file -
AddType text/x-server-parsed-html .html
This will make .html pages work with SSI so you won't have to use .shtml pages.
$cgi::mailprogram= "/usr/sbin/sendmail";
init();
sub init
{
print "Content-type: text/html\n\n";
$env::query_string= $ENV { 'QUERY_STRING' };
my @query_tab= split ( /\&/, $env::query_string );
my $query;
foreach $query ( @query_tab )
{
$query=~ s/\+/ /go;
my ( $key, $val )= split ( /\=/, $query, 2 );
# Convert %XX from hex numbers to alphanumeric
$key=~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
$val=~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
if ( $key eq "insert") { $ssi::insert= $val;}
if ( $key eq "from") { $ssi::from= $val;}
if ( $key eq "arb") { $ssi::arb= $val;}
}
$env::remote_host= $ENV { 'REMOTE_HOST' };#Apache V1.3 does not set
if (! $env::remote_host ){ $env::remote_host= $ENV { 'REMOTE_ADDR' } }
if ( index ( $ENV { 'REQUEST_URI'},'.htm?as=no') > 0) { noad ( "REQUEST_URI with .htm?as=no") }
if ( index ( $ENV { 'HTTP_REFERER'},'.htm?as=no') > 0) { noad ( "HTTP_REFERER with .htm?as=no") }
if ( index ( $ENV { 'HTTP_USER_AGENT' },'Alexa Toolbar YYYYMMDD') > 0) { noad ( "My wife visits") }
if ( $env::remote_host eq "unwanted visitor") { noad ( "unwanted visitor") }
my $file= "../admin/source/$ssi::from.txt";
my ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks )
= stat ( $file );
if (! $ctime )
{#no file found
$ssi::message.= "
Can not open $file";
message ();
return;
}#no file found
open( GET_SOURCE,$file);
binmode( GET_SOURCE);
sysread( GET_SOURCE,$ssi::file, $size);
close( GET_SOURCE);
my $ad= extract ( "$ssi::alt$ssi::insert" );
$ssi::arb=~ s/\ /\%20/g;
$ad=~ s/AMAZON_RB/$ssi::arb/g;
message ();
print $ad;
}
sub noad
{
my ( $message )= @_;
$ssi::message.= "\n$message";
$ssi::alt= "alt.";
}
sub extract
{
my ( $key )= @_;
my $text_search= "\n$key=";
my $val= "\n$ssi::file\n";
my $text_index_begin= index ( $val, $text_search );
if ( $text_index_begin < 0 )
{#begin not found
$ssi::message.= "
from $ssi::from insert $ssi::insert text $key
begin not found";
return "";
}#begin not found
my $text_index_end;
{#container block found, extract text
$text_index_end= rindex ( $val, $text_search . "END" );
if ( $text_index_begin < $text_index_end ){ last }
$text_index_end= index ( $val, "\n", $text_index_begin + 1 );
if ( $text_index_end >= 0 ){ last }
$ssi::message.= "
from $ssi::from insert $ssi::insert text $key
end not found";
return "";
}#container block found, extract text
my $text_search_length= length ( $text_search );
$val= substr ( $val, $text_index_begin + $text_search_length,
$text_index_end - $text_index_begin - $text_search_length );
return $val;
}
sub message
{
if (! $ssi::message ) { return }
open ( MAIL,"¦$cgi::mailprogram -t" );
print MAIL "To: webmaster\@example.com (Jettero Heller)
From: script\@$ENV{'SERVER_NAME'} (script error report)
Subject: error report - $ENV{'SCRIPT_URI'}
The following problems occured:
$ssi::message
";my $k; foreach $k ( keys %ENV ) { my $v = $ENV{$k}; print MAIL "\n[ $k ]=[ $v ]"; }
close(MAIL);
}
_______________________________________
The file contsains
300x250=
AdSense code for 300x250
300x250=END
alt.300x250=
Code to be shown instead of AdSense
alt.300x250=END
call is like
<!--#include virtual="/cgi-bin/ssi.pl?from=google-g&insert=300x250&arb=Theme" -->
arb means Amazon recommended book
This parameter is used to display recommended books about a theme.
from=google-g means from what file to load. google-g contains the code with the German channels and also the alt code for German.