We Got 2 files for use
grab_lib.php && index.php
OOP BASED SCRIPT :
grab_lib.php
CLASSIC PHP :
index.php
you can use this class for easy switching between grabbing methods file_get_contents (fget) and curl both methods implemented with user agent .
class attached bellow
grab_lib.php && index.php
OOP BASED SCRIPT :
grab_lib.php
PHP Code:
<?php
class grabber{
var $grab;
function page($url,$mode){
//empty ? // fallin' back to file_get_contents
if (empty($mode)){$mode='fget';}
if ($mode=='fget'){
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"User-Agent: SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)\r\n"
)
);
$context = stream_context_create($opts);
// Send HTTP headers set above thiss allow us to set browser model
$page=file_get_contents($url, false, $context);
$ret = $this->grab=$page;
}
if ($mode=='curl'){
$crl = curl_init();
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl,CURLOPT_USERAGENT,'SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)');
//Make sure its sent , send user agent via header to
curl_setopt ($crl, CURLOPT_HTTPHEADER,array('User-Agent: SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html),'));
curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
$grab = curl_exec($crl); curl_close($crl);
$page=$grab;
$ret = $this->grab=$page;
}
//echo 'Using '.$mode.' fetching contents';
return $ret; }
}
?>
CLASSIC PHP :
index.php
PHP Code:
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Here is my link grabber demo</title>
</head>
<body>
<?php
###############################
require_once'grab_lib.php'; #
###############################
$grab = new grabber();
########### FILE LINKS ONLY ############
$moddmydata = $grab->page('http://whatmp3.name/search.php?query=house+base','curl');
// make local links
$moddmydata = str_replace("http://whatmp3.name/","",$moddmydata);
// remove all div's on page
$moddmydata = preg_replace('/<div(.*?)>/is','',$moddmydata);
$moddmydata = str_replace('</div>','',$moddmydata);
// remove all scripts on page
$moddmydata = preg_replace('/<script(.*?)<\/script>/is','',$moddmydata);
// remove all images
$moddmydata = preg_replace('/<img(.*?)>/is','',$moddmydata);
// here you can mod the links
$moddmydata = preg_replace('/<a href="download.php(.*?)">/is','<a href="my_file.php$1&act=download">',$moddmydata);
// remove all ads links ussualy starts with http://
//site links should be local pointing like /file.php?file=12453
$moddmydata = preg_replace('/<a href="http:\/\/(.*?)<\/a>/is','',$moddmydata);
$moddmydata = preg_replace("/(.*?)<a href=\"(.*?)<\/a>/is","<a href=\"$2</a></br>\n",$moddmydata);
$moddmydata = preg_replace("/<!--(.*?)<\/html>/is","",$moddmydata);
echo $moddmydata;
?>
</body>
</html>
you can use this class for easy switching between grabbing methods file_get_contents (fget) and curl both methods implemented with user agent .
class attached bellow