Greg
09-14-2005, 11:43 PM
Now that we can publish adsense and ypn ads on our web pages, many people will want to try both programs simultaniously. This code will assure that you only show adsense or ypn and not a mix of both no matter how many ads you have on a page. This is necessary since we can have up to three adsense units and one adlinks unit per page. I believe the number of ypn ads is yet to be set in stone. This method will hopefully work well no matter how many pages you have So here we go...
Create ad files. You should store them above your web root folder and use file system relative paths.
ie. /home/account_name/ad_files/ad_file.html
If you have more then one ad on a page, create multiple files. Here are some examples of naming the ad files.
adsense.html
ypn.html
adsense_1.html
ypn_1.html
adsense_page_name_x.html (x represents the ad number for pages with multiple ads)
ypn_page_name_x.html
adsense_ch_xxxxxxxxx.html (xxxxxxxxx represents an ad channel)
ypn_ch_xxxxxxxxxx.html
adsense_460x60.html (460x60 represents an ad size)
ypn_460x60.html
You are smart folks and will come up with a naming convention that works well for you.
Again, you should store them above your web root folder and use file system relative paths for the best results.
ie. /home/account_name/ad_files/ad_file.html
We will show examples for .html pages that parse php and php pages.
Instructions for .php and .html pages that will parse php.
Before the first ad place this code...
<?php
$show_adsense = rand(0,1);
?>
Now for each ad, use this code. The adsense code will always go first in our conditionals.
<?php
if($show_adsense)
{
include("/home/account_name/ad_files/adsense_1.html");
}
else
{
include("/home/account_name/ad_files/ypn_1.html");
}
?>
For the second and so on...
<?php
if($show_adsense)
{
include("/home/account_name/ad_files/adsense_2.html");
}
else
{
include("/home/account_name/ad_files/ypn_2.html");
}
?>
For the so on part, replace the file names for the third ad and so on...
Remember, you can use any filename for the ad code file that will identify what ad code is in each that is best for you to identify them.
To use the adsense or ypn code in a php file as variables, use the following code. Then you can echo the code where you need it...
$show_adsense = rand(0,1);
if($show_adsense)
{
$ad_1 = file_get_contents("/home/account_name/ad_files/adsense_1.html");
}
else
{
$ad_1 = file_get_contents("/home/account_name/ad_files/ypn_1.html");
}
if($show_adsense)
{
$ad_2 = file_get_contents("/home/account_name/ad_files/adsense_2.html");
}
else
{
$ad_2 = file_get_contents("/home/account_name/ad_files/ypn_2.html");
}
Or you can condense the code...
$show_adsense = rand(0,1);
if($show_adsense)
{
$ad_1 = file_get_contents("/home/account_name/ad_files/adsense_1.html");
$ad_2 = file_get_contents("/home/account_name/ad_files/adsense_2.html");
}
else
{
$ad_1 = file_get_contents("/home/account_name/ad_files/ypn_1.html");
$ad_2 = file_get_contents("/home/account_name/ad_files/ypn_2.html");
}
To display the ad, place the following where appropreate.
echo $ad_1;
echo $ad_2;
Continue on and use $ad_3 and $ad_4 as needed and duplicate the above code to fetch the needed ad files.
Here are examples to try and attached are the source code.
Alternating Ads in a HTML File That Parses PHP (http://www.lakecs.com/test_ad_code.html)
Alternating Ads in a PHP File as Variables (http://www.lakecs.com/test_ad_code.php)
Enjoy your ad revenue and remember to always work within the program TOS.
Good Luck.
Create ad files. You should store them above your web root folder and use file system relative paths.
ie. /home/account_name/ad_files/ad_file.html
If you have more then one ad on a page, create multiple files. Here are some examples of naming the ad files.
adsense.html
ypn.html
adsense_1.html
ypn_1.html
adsense_page_name_x.html (x represents the ad number for pages with multiple ads)
ypn_page_name_x.html
adsense_ch_xxxxxxxxx.html (xxxxxxxxx represents an ad channel)
ypn_ch_xxxxxxxxxx.html
adsense_460x60.html (460x60 represents an ad size)
ypn_460x60.html
You are smart folks and will come up with a naming convention that works well for you.
Again, you should store them above your web root folder and use file system relative paths for the best results.
ie. /home/account_name/ad_files/ad_file.html
We will show examples for .html pages that parse php and php pages.
Instructions for .php and .html pages that will parse php.
Before the first ad place this code...
<?php
$show_adsense = rand(0,1);
?>
Now for each ad, use this code. The adsense code will always go first in our conditionals.
<?php
if($show_adsense)
{
include("/home/account_name/ad_files/adsense_1.html");
}
else
{
include("/home/account_name/ad_files/ypn_1.html");
}
?>
For the second and so on...
<?php
if($show_adsense)
{
include("/home/account_name/ad_files/adsense_2.html");
}
else
{
include("/home/account_name/ad_files/ypn_2.html");
}
?>
For the so on part, replace the file names for the third ad and so on...
Remember, you can use any filename for the ad code file that will identify what ad code is in each that is best for you to identify them.
To use the adsense or ypn code in a php file as variables, use the following code. Then you can echo the code where you need it...
$show_adsense = rand(0,1);
if($show_adsense)
{
$ad_1 = file_get_contents("/home/account_name/ad_files/adsense_1.html");
}
else
{
$ad_1 = file_get_contents("/home/account_name/ad_files/ypn_1.html");
}
if($show_adsense)
{
$ad_2 = file_get_contents("/home/account_name/ad_files/adsense_2.html");
}
else
{
$ad_2 = file_get_contents("/home/account_name/ad_files/ypn_2.html");
}
Or you can condense the code...
$show_adsense = rand(0,1);
if($show_adsense)
{
$ad_1 = file_get_contents("/home/account_name/ad_files/adsense_1.html");
$ad_2 = file_get_contents("/home/account_name/ad_files/adsense_2.html");
}
else
{
$ad_1 = file_get_contents("/home/account_name/ad_files/ypn_1.html");
$ad_2 = file_get_contents("/home/account_name/ad_files/ypn_2.html");
}
To display the ad, place the following where appropreate.
echo $ad_1;
echo $ad_2;
Continue on and use $ad_3 and $ad_4 as needed and duplicate the above code to fetch the needed ad files.
Here are examples to try and attached are the source code.
Alternating Ads in a HTML File That Parses PHP (http://www.lakecs.com/test_ad_code.html)
Alternating Ads in a PHP File as Variables (http://www.lakecs.com/test_ad_code.php)
Enjoy your ad revenue and remember to always work within the program TOS.
Good Luck.