Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Account 961712
- Total Paid $0.00
- Clicks Balance $0.00
- Conversion Balance $0.00
- LOGOUT |SUPPORT
- $Recommend
- ACCOUNT MANAGEMENT
- MANAGE BIDVERTISERS
- MANAGE TOOLBARS
- MANAGE XML
- REPORTS
- XML Feeds Center Add new XML feed Daily Report Summary Report Geo Report
- PHP Feed Implementation
- PHP Sample XML Feed Implementation:
- Sample PHP code is provided for a quick implementation of our XML feed - you can use the following PHP code as an implementation sample to get you started:
- Your XML Feed Request Format:
- <?php
- ini_set('display_errors', 'On');
- error_reporting(E_ALL | E_STRICT);
- $pid = '425245';
- $bid = '1065331';
- $ownid = 'xml1'; // if sending traffic with sub affiliates. modify to fit your needs.
- $maxcount = '5'; // max number of results to return. modify to fit your needs.
- $u_agnt = urlencode($_SERVER['HTTP_USER_AGENT']); // user agent. do not modify
- $cip = $_SERVER['REMOTE_ADDR']; // IP address of user requesting search. do not modify
- // acquire search terms
- if(isset($_REQUEST['terms']) && !empty($_REQUEST['terms'])){
- $terms = urlencode($_REQUEST['terms']);
- }else{
- echo get_search_form();
- exit;
- }
- $bvref = trim($_SERVER['HTTP_REFERER']);
- $url = "http://bdv.bidvertiser.com/BidVertiser.dbm?pid=$pid&bid=$bid&Kterm=$terms&cip=$cip&maxcount=$maxcount"
- ."&bvref=$bvref&u_agnt=$u_agnt&ownid=$ownid&xml=1";
- $result = call_xml($url, $u_agnt);
- // check if results came back from the feed
- if (strstr($result, "title") === FALSE) { $msg = "No results found.";}else{$msg="";}
- echo get_search_form($terms, $msg);
- echo format_result($result);
- /*
- Parses and display the result of the XML feed
- @param $result - The result of the XML feed
- @returns - the HTML version of the XML results
- */
- function format_result($result){
- $title = array();
- $url = array();
- $redirect = array();
- $description = array();
- preg_match_all('#<title><!\[CDATA\[(.*?)\]\]></title>#', $result, $title);
- preg_match_all('#<displayURL><!\[CDATA\[(.*?)\]\]></displayURL>#', $result, $url);
- preg_match_all('#<redirect><!\[CDATA\[(.*?)\]\]></redirect>#', $result, $redirect);
- preg_match_all('#<description><!\[CDATA\[(.*?)\]\]></description>#', $result, $description);
- $items = count($title[1]);
- $rv = '';
- for($i=0; $i<$items; $i++){
- $rv .= '
- <li>
- <a href='.$redirect[1][$i].'>'.$title[1][$i].'</a><br>
- '.$description[1][$i].'<br>'.
- $url[1][$i].
- '<br><br></li>';
- }// end for
- return $rv;
- }// end function
- /*
- Obtains the search form
- @param $terms - the default search term
- @param $msg - alert message
- @returns - The HTML form
- */
- function get_search_form($terms="", $msg=""){
- if (!empty($msg)) {
- $msg = "<font color='red'><b>$msg</b></font><hr>";
- }// end if
- $form = "
- $msg
- Please enter your search term
- <br><br>
- <form method='post' action='".$_SERVER["PHP_SELF"]."'>
- Keyword: <input type='text' name='terms' value='$terms'>
- <br>
- <br>
- <input type='submit' value='Search'>
- </form><hr>
- ";
- return $form;
- }// end function
- /*
- Calls the XML feed
- @param $url - the URL of the feed to call
- @param $ua - The user agent
- @returns - the result of the query from the feed
- */
- function call_xml($url, $ua="")
- {
- $hostname=trim($_SERVER['HTTP_HOST']);
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_USERAGENT, $ua);
- curl_setopt($ch, CURLOPT_REFERER, $hostname);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- }// end function
- ?>
- Copyright © 2011, BidVertiser.com All rights reserved. BidVertiser.com is a division of Bpath, LTD.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement