Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Implement pop under advertising to your site using pop under class

Pop under class allows you to implement pop under advertising to your website.

You can customize probability of ads to appear, time for how long to show advertisement and much more.

There is also an option to mark users who saw advertisement for specified period of time, so they won't be bothered with pop under advertisements during that specified period.

You can also specify advertisement URL and unique ID (optional to track showed advertisements and whether they were skipped by users or watched fully using callback function).

Language and template files included to provide full outlook customization

Easiest implementation you'll ever have, just check out example file codes at phpclasses.org

Contents

Download

Example codes

Simple example:

<?php

//declaring class instance
include("./pop_under.class.php");
$popunder = new pop_under();

//putting in link to show with optional title text
$popunder->add_url("http://code-snippets.co.cc/", "Code snippets");
$popunder->add_url("http://www.phpclasses.org/browse/author/838850.html", 
                    "Arturs Sosin's PHP classes");

//for testing purpose visitors won't be marked
$popunder->use_mark(false);

//and of course showing ads
//put this before any other output
$popunder->show_ads();


//and some content goes here
echo "<p>Content</p>";
echo "<p>Default probability of popunder to appear is 10% ";
echo "on every pageview, so just keep refreshing till you get it ;)</p>";
echo "<p><a href='?id=".($_GET['id']+1)."'>Goto ".($_GET['id']+1)."</a></p>";

?>

Examples in action

Example scripts provided with package in action:

Method list

Get errors

Back to method list

Method nameget_errors()
DescriptionReturns array with errors or empty array if there was no errors
Example output
Array
(
    [0] => Timer can not be negative. Previous or default value will be used
)

Set advertisment timer

Back to method list

Method nameset_timer($sec)
DescriptionSets the timer for how long to display advertisment in seconds. Default value 10 seconds
Input parametersint $sec - time in seconds how long to display advertisment
Example inputset_timer(10)

Set probability of pop under to appear

Back to method list

Method nameset_probability($percent)
DescriptionSets the probability in percent for advertisment to appear, while browsing website. Default value 10%
Input parametersint $percent - value bigger than 1 and lesser or eqaul then 100. 100% - every page refresh advertisment will be showed
Example inputset_probability(50)

Allow or disallow visitor to skip advertisment

Back to method list

Method nameset_exit($bool)
DescriptionAllows or dissallows visitors to skip advertisment by clicking specific link. Refresh page won't skip advertisment, it will be loaded from the start. Default value: allow to skip advertisments
Input parametersboolean $bool - true: show skip option, false: don't allow to skip advertisment
Example inputset_exit(false)

Mark visitors who already saw advertisment

Back to method list

Method nameuse_mark($bool)
DescriptionAllows to mark visitors, using cookies, to whom advertisment already appear, so they won't be bothered with it for a specified period of time using set_period method. After specified period of time, visitor will be shown advertisment with specified probability. Default value: mark visitors
Input parametersboolean $bool - true: mark visitors and don't show advertisment for specified period of time, false: don't mark visitors and show advertisment with probability to appear
Example inputuse_mark(false)

Set period of time not to show advertisment

Back to method list

Method nameset_period($sec)
DescriptionSets the period of time not to show advertisments to marked visitors (who already saw one advertisment). Default value 1 day
Input parametersint $sec - specifies period of time in seconds
Example inputset_period(6400)

Add advertisment to show

Back to method list

Method nameadd_url($src, $title = "", $id = "")
DescriptionAdd advertisment to show randomly to website visitors
Input parameters

string $src - url of advertisment

string $title - Title of advertisment to appear on top

int $id - unique identifier of advertisment, to notify you via callback function which advertisment was show to visitor

Example inputadd_url("http://code-snippets.co.cc/PHP-classes/Implement-pop-under-advertising-to-your-site-using-pop-under-class", "Pop under class documentation")

Set callback for displaying advertisment

Back to method list

Method nameset_callback($func_name)
DescriptionSets the callback function to call everytime advertisment is displayed, which provides information on which advertisment was shown and was it skipped by user or not. Callback function must take to parameters, unique identifier of advertisment provided with add_url method, and second boolean specifying whether visitor skipped advertisment using exit link. If true - visitor skipped, if false - didn't skip
Input parameters

string $func_name - name of callback function

string $title - Title of advertisment to appear on top

int $id - unique identifier of advertisment, to notify you via callback function which advertisment was show to visitor

Example inputadd_url("http://code-snippets.co.cc/PHP-classes/Implement-pop-under-advertising-to-your-site-using-pop-under-class", "Pop under class documentation")

Show random advertisments

Back to method list

Method nameshow_ads()
DescriptionCombines all settings provided and starts the probability of random advertisments. Without calling this method, advertisments won't appear. You must call this methid before any output to browser. You can use output buffer to ensure this

Possible error messages

List of all errors and meanings

Error textMeaningSolution
Incorrect language array. Default language array will be usedFormat of language array you specified is incorrect

Don't modify keys in array provided in language.php, change only text.

Example format of language array:

Array
{
	'add_to_title' => 'Advertisment', 
	'seconds_left' => 'seconds left', 
	'redirecting' => 'Redirecting', 
	'waiting' => 'Waiting for page to load', 
	'skip' => 'Continue to page'
}
No language array provided. Default language array will be usedNo language array in language.php or language.php doesn't exists

Create language.php in same directory and create and array in it:

$lang = array
(
	"add_to_title" => "Advertisment", 
	"seconds_left" => "seconds left", 
	"redirecting" => "Redirecting", 
	"waiting" => "Waiting for page to load", 
	"skip" => "Continue to page"
);
Timer can not be negative. Previous or default value will be usedYou provided negative value for timerProvide value that is bigger than 0
Porbability can be between 1 and 100 percents. Previous or default value will be usedYou provided percents that are out of 1-100 rangesProvide value that is bigger than 1 and lesser or equal then 100
Period of time can not be negative. Previous or default value will be usedYou provided negative value for periodProvide value that is bigger than 0
Function with specified name: $func_name does not existCallback function your provided, doesn't existProvide valid callback function
No urls to show providedYou didn't provide any advertisment urls to showProvide adverstisment urls

Template

File popunder_template.php contains a template for iframe where advertisments appear. Do not delete or change specified constants: [@constant_name]. You can change only html code. If popunder_template.php is missing, default template will be used form within the cass

Default template:

<html>
<head>
[@title]
[@script]
</head>
<body>
<table style='height:80px; width:100%; text-align: center; border: 0;'>
<tr>
    <td style='width: 70%'>
        <h3>[@popunder_text]</h3>
    </td>
    <td style='width: 30%'>
        <p id='seconds'>[@waiting]</p>
        <p>[@exit]</p>
    </td>
</tr>
</table>
<iframe name='content' src='[@popunder_src]' width='100%' height='100%'/>
<noframes>
<p><a href='[@request_uri]'>[@skip]</a></p>
</noframes>
</body>
</html>

Change language

File language.php contains default texts. You can modify values of array $lang to display your own default texts, but DO NOT modify the keys of array, or else default language array will be used from within the class

Default language file:

<?php
$lang = array
(
    "add_to_title" => "Advertisment", 
    "seconds_left" => "seconds left", 
    "redirecting" => "Redirecting", 
    "waiting" => "Waiting for page to load", 
    "skip" => "Continue to page"
);
?>

Latest changes

None for now

Rate us

Like our script? Rate it at PHP > Hot Scripts

Scripts.com
RATE ME!

Try it out and Rate on PHPclasses.org

Support

PHP classes support forum or comments below

Awards

Pop under class was nominated to Innovation Award and achieved 7th place, thank you for support


You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus