Archive for scripts

create a PPC Search engine with PHP and Searchfeed

So you want to start your own ppc search engine? A ppc search engine may be a good additional income, and you can easilly add it to an established site, or maybe start a new one just for this.

What do I need to start my own ppc search engine?

Well to start you will need a third party network which will provide you the search results. The business scheme is very easy to understand. They give you an automatically way to fetch results based on the keywords that your visitors use to search your site and they pay you for every click that your users do in those results.

Selecting an advertising network for search results

In the past I have used many networks but the only one that was reliable for me was SearchFeed. So in this tutorial I will help you create a ppc search engine using SearchFeed.

Creating your own PPC search engine with SearchFeed

Before you start you will need an account with SearchFeed. If you don’t, use this link to register one, and then come back for the rest of this tutorial :)

The basics

Login to your account at SearchFeed, and go to Integration Tools > XML and Text Usage. From there you will see your track identification number (trackID) and your partner identification number (pID). Those are very important as they are used by SearchFeed to assign the clicks to your account.

The script. Time to create our php search engine

The above code is very basic. I suppose that you allready have some PhP knowledge in order to work this out. Of course if you have troubles using it you can allways post a question to a PhP forum

function searchFeedResults($q, $results, $tID, $pID)
{
$res = array();
$url = "http://www.searchfeed.com/rd/feed/TextFeed.jsp";
$url.= "?trackID=".$tID."&excID=&pID=".$pID."&cat=";
$url.= urlencode($_GET['q']).”&nl=”;
$url.= $results.”&page=1&ip=”.$_SERVER["REMOTE_ADDR"];
$ret=file($url);
if ( count($ret) == 0 ) return $res;
for ( $i=0;$i {
$j = $i;
for ( $j=$i;$j<($i+4);$j++)
{
$a = explode('|',$ret[$j]);
$tmp[] = $a[2];
}
$res [] = $tmp;
unset($tmp);
}
return $res;
}

This function (searchFeedResults) gets the results and returns an array with them. The parameters are :

  • $q => The query (search terms)
  • $results => How many results to display
  • $tID => Your SearchFeed track id
  • $pID => Your SearchFeed partner id

How to use the script

Here is a common usage of the script. I suppose that the user is using $_GET['q'] to send a query. So here is how we can parse it:

$results = searchFeedResults($_GET['q'], 20, $myTid, $myPid);
if ( $results ){
foreach ( $results as $rec ){
echo ‘
<p>
<a href=”‘.$rec[2].’” onmouseover=”window.status=\’http://’.$rec[1].’\'; return true”
onmouseout=”window.status=\’ \’; return true”>’.$rec[0].’</a><br />
‘.$rec[3].’<br />
<small>’.$rec[1].’</small>
</p>’;
}
}else{
echo ‘No results for ‘.$_GET['q'].’<br /><br />’;
}

Conclusions

Hope you like our script. By the way I have also added a full working script, which you can download here.