Posts Tagged ‘Free Code’

Dynamically Generating Webpages – Insert Video

 |  Free Code, PHP, SEO, Video, Website Development  |  Comments Off

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:

<?php 

class youtube{ 

    function get_youtubevideo($theproduct){
        ///do youtube stuff
        $theproductencoded=urlencode($theproduct);
        $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
        curl_close($ch);
        $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>
        </object>";
        } 

        // 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>";
        }
        $contentcenter.="</div>";
        return $contentcenter;
    }
}

?>

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

include_once("youtube_class.php");
$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.

link.php

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

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.

offer.php

<?php
$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 First-name and Last-name Databases (CSV and SQL)

free_first_and_lastname_database_csv

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

enjoy.

Quietaffiliate userping