Uchase pay-per-click search (Rated 0)Description:
Very small, simple, and easy to install script that will add value to your website and will generate income for you everytime somebody uses it and clicks on the search results. You need to register as an affiliate at uchase.com and change the affiliate id in the script to get paid. When user tipes in a search term and hits submit, XML feed from uchase.com is pooled by the script, parsed, and results are displayed on your website. You can completely change the design of search box and output result pages to suit your website using HTML and CSS Code starts here
<?
/*******************************/
//Configuration
//please make appropriate settings
//your uchase affiliate id
$affiliateid=1000;
//the maximum number of results you
$maxres=10;
//change this if you want a hard coded keyword value; use urlencode() function,
// for example: $keyword=urlencode("free cigarettes for kids");
$keyword=urlencode($_GET['search']);
/*******************************/
//there is no need to change anything below this line except the footer where you can
include "./header.php";
if($keyword){
$file = "http://www.uchase.test/xml/xmlfeed.php?a=".$affiliateid."&kw=".$keyword."&maxres=".$maxres."&ip=".$HTTP_SERVER_VARS["REMOTE_ADDR"];
echo $file;
if($_GET['page']) $file.="&page=".$_GET['page'];
$results = array();
$params=array();
$linknum=0;
function startElement($parser, $name, $attrs)
{
global $linknum, $params;
switch($name){
case "RECORD":
$linknum++;
break;
case "RESULTS":
while(list($k,$v)=each($attrs)) $params[strtolower($k)]=$v;
break;
}
}
function endElement($parser, $name)
{
global $results, $linknum, $thedata;
switch($name){
case "TITLE":
$results[$linknum]["title"].=$thedata;
break;
case "DESCRIPTION":
$results[$linknum]["description"].=$thedata;
break;
case "DISPLAYURL":
$results[$linknum]["displayurl"].=$thedata;
break;
case "CLICKURL":
$results[$linknum]["clickurl"].=$thedata;
break;
}
$thedata="";
}
function characterData($parser, $data) {
global $results, $linknum, $thedata;
$thedata.=$data;
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
//header
echo $params['total']." results found<br> Shown results from ".$params['from']." to ".$params['to']."<br><br>";
for($i=1;$i<=$linknum;$i++){
echo "<a class=resulttitle target=_self href=".$results[$i]['clickurl'].">".$results[$i]['title']."</a><br><span class=resultdescription>".$results[$i]['description']."</span><br><span class=resulturl>".$results[$i]['displayurl']."</span><br><br>";
}
//
xml_parser_free($xml_parser);
$pages=ceil($params['total']/$maxres);
for($i=0;$i<$pages;$i++){
echo " | ";
if($i!=$params['page']) echo "<a class=pages href=".$HTTP_SELF."?search=".urlencode($search)."&page=".($i).">";
echo ($i+1);
if($i!=$params['page']) echo "</a>";
echo " | ";
}
}else{
echo "Please enter a phrase to search";
}
//the html footer foloows. You can change it to you likeing
include "./footer.htm";
?>
Submitted by uchase on 02-09-2004 8:08 |