Dynamically Generating Webpages – Insert Video

This is just a teaser for a series of articles on dynamically creating webpages on the fly based on keywords. Whether it’s based on a list of related keywords to your target set or simply based on what a user is searching for, the more content that you can provide related to the term, the better off your chances of it being ranked well in the serps (not to mention will provide a better user experience).

Here’s an easy one for you, it will pull a youtube video based on whatever keyword you give it. For use in a wordpress installation, make sure to enable the Exec-PHP plugin before inserting the code.

There are two parts to this, the youtube class and then the actual code to call it and display the video. This was taken long ago from a post on WF, though has been slightly modded. I forget who originally provided it but thanks. 🙂

Instead of having one huge php file with all the various functions, I’ve found it easier to separate each task into separate class files, that way on the actual page I only need to use the include() function and call up the script using my keyword.

Create a file called youtube_class.php and insert the following code:


class youtube{ 
    function get_youtubevideo($theproduct){                 
        ///do youtube stuff     
        $apicall = "http://gdata.youtube.com/feeds/videos?vq=$theproductencoded&max-results=1";         
        //Initialize the Curl session 
        $ch = curl_init();         
        //Set curl to return the data instead of printing it to the browser. 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);         
        //Set the URL 
        curl_setopt($ch, CURLOPT_URL, $apicall);         
        //Execute the fetch 
        $data = curl_exec($ch);         
        //Close the connection 
        $xml = new SimpleXMLElement($data);                     
        // Check to see if the XML response was loaded, else print an error 
        $contentcenter.="<div class="leftside">";         
        //show the video if a video was found         
        if (!empty($xml->entry)) {             
        $media = $xml->entry->children('http://search.yahoo.com/mrss/');         
        $vidtitle= $media->group->title;         
        $vid= $media->group->content->attributes()->url;             
        $contentcenter.="<h1>Video for " . str_replace("-"," ",ucwords($theproduct)). "</h1>";                     
        $results = '';         
        // If the XML response was loaded, parse it and build links          
        $vid = str_replace("?v=", "v/", $vid);          
        // For each SearchResultItem node, build a link and append it to $results         
        $contentcenter.= "<object width="425" height="355"> 
        <param name="movie" value="$vid"></param> 
        <param name="wmode" value="transparent"></param> 
        <embed src="$vid" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed> 
        // If there was no XML response, print an error         
        else {             
            //$results = "Dang! Must not have got the XML response!"; 
            $contentcenter .= "<h2>Error: No video found</h2>";                     
        return $contentcenter;         


Now on whatever page you’d like to display the youtube video, simply insert the following code:

$theproduct = 'topic';
$videoshow = new youtube();
echo $videoshow->get_youtubevideo($theproduct);

Typically you’ll have the keyword that you’re using to generate the dynamic page already stored as a variable, in which case you can just replace $theproduct = ‘topic’; with your variable(i.e. $searchkeyword).

Cloak And Rotate Your Affiliate Links!

Here’s a simple php script that you can use to not only cloak the referrer information, but also to rotate through your affiliate links so that you can test different offers and/or different advertising networks.

In order to hide your traffic sources you need to send the user through a double-redirect before pushing them along to the advertisers page. This can be done many different ways, but for the sake of this post I’m just going to use a very basic PHP redirect. For this setup, have the offer link on your landing page point to link.php, which will immediately redirect them to offer.php. Once they reach offer.php it will randomly select one of the affiliate links and redirect them on to their final destination. It’s that simple.


/* Redirect browser */
header("Location: offer.php");
/* Now the next line just makes sure that code below does not get executed when we redirect. */

Now here’s the second file – You’ll want to replace the URL’s with YOUR affiliate links. If you’d like to add or remove offers just add or remove one of the “$affiliateoffer[] = ‘http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=1788&t202kw='” lines.


$r = $_GET['sub'];
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=1788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=2788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=3788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=4788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=5788&t202kw=';
srand ((double) microtime() * 1000000);
$random_number = rand(0,count($affiliateoffer)-1);
$dur = ($affiliateoffer[$random_number]);
$moneysite = $dur.$r;
header("Location: $moneysite");

There you go, now you’re safeguarding your leads as well as testing out networks/offers. Remember, the secret to having sustainable campaigns is to always be testing!

Free PHP Source Code: A/B Split Testing For Your Landing Pages

As with any type of marketing, you should always be testing new ideas + strategies in every facet of your work. The most important and most typically overlooked form of testing that is essential to getting a profitable conversion rate is in testing your squeeze or landing pages. Switch everything up! The images, the copy, heck even the entire layout + domain. You’ll never know what will make you money/convert until you actually find it and the best way to setup your site to systematically rotate through different landing page variations is by A/B testing (or in this case you could actually take it from A-Z as far as different destinations for your users). It’s just a small little php script that you put at the top of any page you’re sending traffic to. After each new referral comes through it just goes down the list of pages (you can also use domains if you wanted to try out different URIs). It’s that simple + there’s very little chance anyone will even realize they’re being redirected. Enjoy!

   if (!empty($_SERVER['HTTP_REFERER'])) {
      $currentPage = $_SERVER['PHP_SELF'];
      echo '<meta http-equiv="refresh" content="0; url='. $currentPage .'">';

   $domains   = array();
   $domains[] = 'quietaffiliate.com';
   $domains[] = 'twitter.com/quietaffiliate';
   $domains[] = 'wickedfire.com';

   $ct = count($domains)-1;
   $currentDomain = $domains[rand(0, $ct)];

   header("Location: http://www.$currentDomain/", TRUE, 301);

PHP Script To Fetch Title, Keyword and Description Tags


Someone recently asked for a way to quickly pull basic page info from a website, so I thought I’d go ahead and share the code for a very easy PHP script that will retrieve the page title, meta keywords and meta description for any website.

$url = “http://www.shamwow.com";
$fp = fopen( $url, ‘r’ );
$content = “”;
while( !feof( $fp ) ) {
$buffer = trim( fgets( $fp, 4096 ) );
$content .= $buffer;
$start = ‘<title>’;
$end = ‘</title>’;
preg_match( “/$start(.*)$end/s”, $content, $match );
$title = $match[ 1 ]; 
$metatagarray = get_meta_tags( $url );
$keywords = $metatagarray[ "keywords" ];
$description = $metatagarray[ "description" ];  

echo “<div><strong>URL:</strong> $url</div>n”;
echo “<div><strong>Title:</strong> $title</div>n”;
echo “<div><strong>Description:</strong> $description</div>n”;
echo “<div><strong>Keywords:</strong> $keywords</div>n”; 

There’s your basic script. Replace where it says www.shamwow.com with whatever site you want to pull data from. The results will look like this:

URL: http://www.shamwow.com
Title: ShamWow® Official Website РHolds 12 Times Its Weight In Liquid
Description: You’ll Be Saying Wow Every Time!
Keywords:You’ll Be Saying Wow Every Time!, official tv website, as seen on tv

Where to go from here? There are millions of different uses from SERP reporting to page title & keyword comparison. Heck, you could even throw a form on it and present it as an SEO tool on your website (almost every ‘toolset’ you find online has something similar)….

Free First-name and Last-name Databases (CSV and SQL)


Matt over on the WF forums had recently posted a SQL database that he had created comprised of first and last names, a great resource to have handy when auto-generating identities, accounts, comment authors, etc.. While it was a pretty large list, it still wasn’t as complete as the one i’ve been using over the years (also it was separated by gender and used one giant table instead of segmenting the first and last names into two). I figured that if I was going to complain about something free, I might as well provide something in return, so here’s your chance to download a free first and last name database in both SQL and CSV formats (pick your poison). There are a total of 5494 first-names and 88799 last-names allowing for a never-ending source of randomly generated full names.

Free Name Database Download – SQL:
.sql File | .zip File

Free Name Database Download – CSV:
First Names (5494) – .csv File & Last Names (88799) – .csv File
I also compressed them both for easy download – .zip of both files


Break out of ANY iFrame (Including Google Image Search)

Have a video game portal and you’re tired of folks iframing their own ads around your games? Want to break the google image iframe when it reaches your site? Easy, just copy and paste this code at the top of your file and it’ll break you out of any iframe. For large sites it’s best to put it in an external .js file and just use an include call at the top of each page:

<script type="text/javascript">
		if (top.location!= self.location) {
			top.location = self.location.href


Countdown Timer Redirect Javascript For Your Affiliate Links

Affiliate Link Countdown Clock

A great way to scrub referrals (and help cloak affiliate links from Google) is by sending your users to a ‘middleman’ redirect page before handing them off to the Advertiser. With some offers though it’d be nice to be able to deliver one final ‘parting’ message or chance for up-sell before having them leave your site. For those situations I’ve found it handy to build out the ‘middleman’ pages using a javascript redirect timer that lets me delay the eventual redirect for however long I think is necessary for the visitor to read my farewell message or see that ‘last-minute-offer.’

So that the user will know this is all part of the website experience, a simple countdown timer is shown letting them see how much time is left before the page changes. There’s even a secondary option in the script that allows for a short one-liner to be displayed during the eventual redirect, though the transition is typically too quick for anyone to read (so it isn’t mandatory, if left blank it will default to say “Redirecting…”).

Download countdownRedirect.js

 * Copyright (C) 2006-2009, QuietAffiliate.com. All rights reserved.
 * Script Name: Countdown Redirect
 * You can obtain this script at http://www.QuietAffiliate.com

function countdownRedirect(url, msg)
   var DEF_MSG = "Redirecting...";

   if( ! msg )
      msg = DEF_MSG;

   if( ! url )
      throw new Error('You didn't include the "url" parameter');

   var e = document.getElementById(TARG_ID);

   if( ! e )
      throw new Error('"COUNTDOWN_REDIRECT" element id not found');

   var cTicks = parseInt(e.innerHTML);

   var timer = setInterval(function()
      if( cTicks )
         e.innerHTML = --cTicks;
         document.body.innerHTML = msg;
         location = url;	  

   }, 1000);

To use just upload the countdownRedirect.js script to your webserver and add the following code to the header on your ‘middleman’ page:

<script src="countdownRedirect.js" type="text/javascript"></script>

In order to have the countdown start automatically once the page is loaded, you’re going to want to then add the ‘onload’ attribute to the main ‘body’ tag. This is also where you’ll tell the script what page to eventually redirect the user to as well as what (if any) redirect message to display:

in this example the eventual redirect will be to http://www.QuietAffiliate.com with no secondary redirect message

<body onload='countdownRedirect("http://www.QuietAffiliate.com")'>

If I wanted to change the default redirect message, “Redirecting…”, to something different (i.e. “Thank You For Visiting”), then I would use:

<body onload='countdownRedirect("http://www.QuietAffiliate.com", "Thank You For Visiting")'>

Now build-out your page as desired. The only thing missing is to tell the script how long the countdown is for and then display the timer on the page. We do that by adding the following code in with our content:

in this example I have the countdown timer set to 10 seconds, you can adjust accordingly

<span class="counter" id="COUNTDOWN_REDIRECT">10</span>

There you go! You can change how the countdown timer looks via CSS. This is the most basic example of how you can use this script but hopefully it saves you some time/gives you some ideas.

Here’s the code for a demo page using the above options:


<title>QuietAffiliate.com Javascript Countdown Redirect Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
body {
   color: black;
   background: white;
   font: bold 18pt Verdana, Arial, Helvetica, sans-serif;
   text-align: center;

span.counter {
   color: red;
   cursor: default;
   font-size: larger;

div.info {
   margin: 0 auto;
   text-align: left;
   font-size: smaller;
   width: 80%;
   margin-top: 2em;

<script src="countdownRedirect.js" type="text/javascript"></script>

<body onload='countdownRedirect("http://www.QuietAffiliate.com", "Thanks For Visiting")'>

<div>QuietAffiliate.com - countdownRedirect.js Demo Page</div>
<div class="info">This is a demo page of the redirect script in action, code and instructions can be found at <strong>QuietAffiliate.com</strong><br /><br /><center>You will automatically be redirected in <span class="counter" id="COUNTDOWN_REDIRECT">10</span> seconds.</center>

Visit Live Demo | Download Demo Page (with countdownRedirect.js)

Free Greasemonkey Script For Facebook Ad Manager

Facebook Ad Manager Greasemonkey Script

Let’s face it, the UI for the Ad Manager in Facebook is horrible, especially if you’ve got a large set of campaigns & are having to deal w/ the ebb and flow of interns rejecting + accepting ads (not to mention deleting/re-submitting them after they’ve been rejected).

Apparently there are other scripts/add-ons available that make this process a whole lot easier, but as was recently pointed out over on the WickedFire Forums, there’s a guy out there who’s actually trying to sell this script for $99.95 (or if you’re dumb enough to send him $25 now to secure your spot in the ‘pre-order’ the script would only be $85 after his discount). He’s since updated his blog to announce that his program would not be released on time after-all, adding that:

…Some rookie on WF totally stole my steam and posted some FireFox plug-in that works pretty sweet with FB to do lots of stuff I had planned.

Well, that rookie just knocked out a working script in one night (while allegedly drunk) meanwhile you’ve only been talking about the project since November 20th….hope you learned a lesson in being quiet.

Nathan from WF from just released what he claims was a drunken coding effort, but regardless is a great Greasemonkey script that streamlines managing Facebook ads. He even was so kind enough to add in a ‘dickroll’ option allowing you to partake in the kind of entertainment that only makemonies.com can provide.

You’ll need the Greasemonkey Firefox add-on in order to use this, install that first from the mozilla add-on site then, after installing & restarting Firefox, download and open (with Firefox) Nathan’s fbo.user.js script (which should then add it to Greasemonkey). Just head on over to the Facebook Ad Manager and partake in your newly acquired abilities of awesomeness.

Some brief features:
Here’s the old campaign screen, forcing you to click through far too many screens just to perform basic ad management functions:
The old Facebook Campaign Screen Before Installing The Greasemonkey Script

Here’s the improved campaign screen, now with added shortcuts:
Facebook Campaign Screen With Greasemonkey Script Installed

Now this wouldn’t be complete without the MakeMonies shout-out…
The Old Menu Bar:
The Facebook Ad Manager Menu Before Installing The Greasemonkey script

The *New* Menu Bar:
The new Facebook Ad Manager Menu After Installing The Greasemonkey Script

Dynamically Generate Users Location On Landing Pages

What? An offer only available if I live in:

Hey, that’s me…sign me up!

Making a user think they’re looking at a local company or offer is an old trick that typically meant you’d have to download and install a location database and then call it using php/perl. Well, not anymore. Part of Google’s AJAX API is a geolocating service. It loads fast + barely takes up any space….great for testimonials or redirected users to specific pages based on their location. It’s a well established marketing theory that consumers will always feel more secure (i.e. more likely to open their wallets up) with someone they can relate to. What’s an instant way to relate to all your customers regardless of how big of an affiliate scum-bag you are? By making them think you’re both from the same city.

It might be a few miles off for some locations and give you the city next door, but over-all it’s pretty spot on and a great little tool that’s only a few lines of code. Best of all, you don’t need any type of Google developer key as it’s not tied to any specific website (i.e. you don’t need to register the site for it to work). Enjoy

Here you go:

<script type="text/javascript" 
<script type="text/javascript">
if (typeof(google.loader.ClientLocation.address.city) != null) {
  +", "
} else {
  document.write("Unknown location")