Skip to content

Instantly share code, notes, and snippets.

@gsdevme
Created November 18, 2018 20:27
Show Gist options
  • Save gsdevme/4ccbadad8a45bba730362634aad67dd3 to your computer and use it in GitHub Desktop.
Save gsdevme/4ccbadad8a45bba730362634aad67dd3 to your computer and use it in GitHub Desktop.
<?php
if(filter_var($_POST['uid'], FILTER_VALIDATE_INT)){//if integer
if((trim($_POST['search']) != '') && ($_POST['uid'] != '') && ($_POST['ip'] != '') && ($_POST['crpyt'] != '') && ($_POST['uid'] != '')){//if they dont equal ''
if(($_POST['crpyt'] == md5($_SERVER['REMOTE_ADDR'])) && ($_POST['ip'] == $_SERVER['REMOTE_ADDR'])){//if md5 hash on the users ip is ok still
include_once($_SERVER['DOCUMENT_ROOT'].'projects/GamePriceComparison/includes/config.php');//include configuration
include_once($root.'includes/preg.php');//includes function & data
include_once($root.'includes/sort.php');//includes function sort2d
//trim & set to vars
$search = trim($_POST['search']);//what the user typed in
$uid = trim($_POST['uid']);//users facebook id
$amazon['scrape'] = "http://www.amazon.co.uk/s/ref=nb_ss?url=search-alias%3Dvideogames&field-keywords=";
$amazon['title'] = "Amazon UK";
$amazon['url'] = "http://amazon.co.uk";
$amazon['preg'] = '<span class="srTitle">(.*?)<\/span>.*?<span class="priceType"><a href="(.*?)">.*?<\/a>:<\/span>.*?<\/span> <span class="saleprice">(.*?)<\/span>';
//amazon search
$scrape = scrape_standard($amazon['preg'], $amazon['scrape'].urlencode($search));//send preg & search url will return a array
$search = trim(strip_tags($scrape[0][1]));//new search string query result from amazon
$searchtitle = $search;//used to output it to the user
//save results to variable
$prices[0]['price'] = str_replace('£',"",htmlentities($scrape[0][3]));
$prices[0]['retailer'] = $amazon['title'];
$prices[0]['link'] = $scrape[0][2];
unset($scrape);
//extract console name from amazon title
$lowercase_search = strtolower($search);//title from the amazon result in lowercase.
$target[1] = "xbox";
$target[2] = "wii";
$target[3] = "ps3";
$target[4] = "pc";
for($i=1;$i<=5;$i++){
if(stristr($lowercase_search, $target[$i]) === FALSE) {
$result = 0;
}else{
$result = $i;
break;
}
}
$string1 = $search;
$needle = "(";
//find length of the needle
$needle_len = strlen($needle);
//find postion
$position_num = strpos($string1,$needle) + $needle_len -1;
//cut the string
$result_string = substr("$string1",0,$position_num);
$search = urlencode(trim($result_string));// the url friendly search used to search the other sites.
//play searches
$searches['play'][0] = NULL;//not used
$searches['play'][1] = "http://www.play.com/Search.aspx?searchtype=X360&searchstring=";//xbox 360
$searches['play'][2] = "http://www.play.com/Search.aspx?searchtype=WII&searchstring=";//wii
$searches['play'][3] = "http://www.play.com/Search.aspx?searchtype=PS3&searchstring=";//ps3
$searches['play'][4] = "http://www.play.com/Search.aspx?searchtype=PC&searchstring=";//pc
//play scrape data
$play['scrape'] = $searches['play'][$result].$search;
$play['title'] = "Play.com";
$play['url'] = "http://play.com";
$play['preg'] = '<\/a><\/div><\/td><td class="wide"><div class="info"><h5> <a href="(.*?)">(.*?)<\/a><span>.*?<\/strong><\/span><\/h5><h6>£(.*?) <span class="orange">';
//scrape play
$scrape = scrape_standard($play['preg'], $play['scrape']);
$prices[1]['price'] = $scrape[0][3];
$prices[1]['retailer'] = $play['title'];
$prices[1]['link'] = $play['url'].$scrape[0][1];
unset($scrape);//clears variable
//asda searches
$searches['asda'][0] = "http://www.asda-entertainment.co.uk/elysium.search?search=";
$searches['asda'][1] = "&searchFilters=WGJveCAzNjAjZGVwYXJ0bWVudDpnYW1lc1wvcGxhdGZvcm1zXC94Ym94XC0zNjAh";//xbox 360
$searches['asda'][2] = "&searchFilters=TmludGVuZG8gV2lpI2RlcGFydG1lbnQ6Z2FtZXNcL3BsYXRmb3Jtc1wvbmludGVuZG9cLXdpaSE%3D";//wii
$searches['asda'][3] = "&searchFilters=UFMzI2RlcGFydG1lbnQ6Z2FtZXNcL3BsYXRmb3Jtc1wvcHMzIQ%3D%3D";//ps3
$searches['asda'][4] = "&searchFilters=UEMjZGVwYXJ0bWVudDpnYW1lc1wvcGxhdGZvcm1zXC9wYyE%3D";//pc
//asda scrape data
$asda['scrape'] = $searches['asda'][0].$search.$searches['asda'][$result];
$asda['title'] = "Asda";
$asda['url'] = "http://www.asda-entertainment.co.uk/";
$asda['preg'] = '<p class="product-name">.*?<a href="(.*?)" title="(.*?)">.*?<\/a>.*?<\/p>.*?<p class="price">.*?<span class="format">.*?<\/span>.*?163;(.*?)<span>Free Delivery<\/span>.*?<\/p>';
//scrape asda
$scrape = scrape_standard($asda['preg'], $asda['scrape']);
$prices[2]['price'] = $scrape[0][3];
$prices[2]['retailer'] = $asda['title'];
$prices[2]['link'] = $asda['url'].$scrape[0][1];
unset($scrape);//clears variable
//zavvi searches
$searches['zavvi'][1] = "http://www.zavvi.com/elysium.search?searchFilters=WGJveCAzNjAjZGVwYXJ0bWVudDpnYW1lc1wvcGxhdGZvcm1zXC94Ym94XC0zNjAh&search=";//xbox 360
$searches['zavvi'][2] = "http://www.zavvi.com/elysium.search?searchFilters=TmludGVuZG8gV2lpI2RlcGFydG1lbnQ6Z2FtZXNcL3BsYXRmb3Jtc1wvbmludGVuZG9cLXdpaSE%3D&search=";//wii
$searches['zavvi'][3] = "http://www.zavvi.com/elysium.search?searchFilters=UFMzI2RlcGFydG1lbnQ6Z2FtZXNcL3BsYXRmb3Jtc1wvcHMzIQ%3D%3D&search=";//ps3
$searches['zavvi'][4] = "http://www.zavvi.com/elysium.search?searchFilters=UEMjZGVwYXJ0bWVudDpnYW1lc1wvcGxhdGZvcm1zXC9wYyE%3D&search=";//pc
//zavvi scrape data
$zavvi['scrape'] = $searches['zavvi'][$result].$search;
$zavvi['title'] = "Zavvi";
$zavvi['url'] = "http://www.zavvi.com/";
$zavvi['preg'] = '<p class="product-name">.*?<a href="(.*?)" title="(.*?)">.*?<\/a>.*?<\/p>.*?<p class="price">.*?<span class="format">.*?<\/span>.*?163;(.*?)<span>Free Delivery<\/span>.*?<\/p>';
//scrape zavvi
$scrape = scrape_standard($zavvi['preg'], $zavvi['scrape']);
$prices[3]['price'] = $scrape[0][3];
$prices[3]['retailer'] = $zavvi['title'];
$prices[3]['link'] = $zavvi['url'].$scrape[0][1];
unset($scrape);//clears variable
//tesco
$searches['tesco'][0] = "http://www.tescoentertainment.com/store/Search.tla/Search?keyword=";
$searches['tesco'][1] = "&navigationstate=%3A8126%3A||0";//xbox 360
$searches['tesco'][2] = "&navigationstate=%3A8128%3A||0";//wii
$searches['tesco'][3] = "&navigationstate=%3A8124%3A||0";//ps3
$searches['tesco'][4] = "&navigationstate=%3A8130%3A||0";//pc
//tesco scrape data
$tesco['scrape'] = $searches['tesco'][0].$search.$searches['tesco'][$result];
$tesco['title'] = "Tesco";
$tesco['url'] = "http://www.tescoentertainment.com";
$tesco['preg'] = '.*?<div class="bi-ct js-buycontainer">.*?<a href="(.*?)">.*?£<\/span>(.*?)<\/p>';
//scrape tesco
$scrape = scrape_standard($tesco['preg'], $tesco['scrape']);
$prices[4]['price'] = $scrape[0][2];
$prices[4]['retailer'] = $tesco['title'];
$prices[4]['link'] = $tesco['url'].$scrape[0][1];
unset($scrape);//clears variable
//output some info to users screen
echo '<h3>You searched for "'.$searchtitle.'", is this correct ? if not <a href="#" onclick="search_again();return false;">search again</a></h3>'."\n";
//debug table
echo '<table cellpadding="0" cellspacing="0" width="100%">'."\n";
echo '<tr class="title">'."\n";
echo '<td><b>User</b></td>'."\n";
echo '<td><b>Search</b></td>'."\n";
echo '<td><b>IP</b></td>'."\n";
echo '</tr>'."\n";
echo '<tr>'."\n";
echo '<td>'.$uid.'</td>'."\n";
echo '<td>'.$search.'</td>'."\n";
echo '<td>'.$ip.'</td>'."\n";
echo '</tr>'."\n";
echo '</table>'."\n";
//end of debug table
//standard table
echo '<table cellpadding="0" cellspacing="0" width="100%">'."\n";
echo '<tr class="title">'."\n";
echo '<td><b>Site</b></td>'."\n";
echo '<td><b>Price</b></td>'."\n";
echo '<td><b>Url</b></td>'."\n";
echo '</tr>'."\n";
foreach($prices as $price){
echo '<tr>'."\n";
echo '<td>'.$price['retailer'].'</td>'."\n";
echo '<td>'.$price['price'].'</td>'."\n";
echo '<td>'.$price['link'].'</td>'."\n";
echo '</tr>'."\n";
}
echo '</table>'."\n";
echo '<script type="text/javascript">$("#result").corner(\'8px\');</script>'."\n";
echo '<script type="text/javascript">frames[\'wallpost\'].window.location="'.$url.'wallpost.php?price='.$prices[0]['price'].'&game="'.$searchtitle.'</script>'."\n";
}else{
die('Unknown Error 3');
}
}else{
die('Unknown Error 2');
}
}else{
die('Unknown Error 1');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment