Hi, CBTSlMob1us!
Here are a code I wrote for you, it require fsockopen and parse_url!
Some of the special of this script is, you can...
1. ... add username and password if it requires, such for memberpages and forums, etc.
2. ... get content from secured line, e.g. "https".
3. ... add your own user-agent name.
4. ... use it to fetch images and other files then for just HTML-documents.
Here it comes ...
PHP Code:
<?php
function getContent( $url, $username = '', $password = '', $user_agent = '' )
{
if( $user_agent == '' )
{
$user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)';
}
@ini_set('user_agent', $user_agent);
if( substr($url, 0, 7) != "http://" )
{
$url = "http://" . $url;
}
$info = parse_url($url);
$path = $info['path'];
$host = $info['host'];
$query = $info['query'];
if( isset($info['port']) && ( $info['port'] != '' ) )
{
$port = $info['port'];
}
else
{
if( $info['scheme'] == 'https' )
{
$port = 443;
}
else
{
$port = 80;
}
}
$port2 = "";
if( $port == 443 )
{
$port2 = ":" . $port;
}
if($query != '')
{
$url = str_replace("?" . $query, '', $url);
$query = str_replace(array("&"), array("&"), $query);
$url = $url . '?' . $query;
}
$fsocket_timeout = 300;
$errno = 0;
$errstr = "";
if ( !($fsock = @fsockopen($host, $port, $errno, $errstr, $fsocket_timeout)) )
{
die("Can't open <i>" . $url . "</i> with fsockopen!");
}
@fputs($fsock, "GET " . $path . " HTTP/1.1\r\n");
@fputs($fsock, "HOST: " . $host . "\r\n");
if( $username != '' )
{
@fputs($fsock, "Authorization: Basic " . base64_encode( $username . ":" . $password ) . "\r\n");
}
@fputs($fsock, "USER-AGENT: " . $user_agent . "\r\n");
@fputs($fsock, "Connection: close\r\n\r\n");
while( !@feof($fsock) )
{
$filedata .= @fread($fsock, 300);
}
@fclose($fsock);
return $filedata;
}
// Add a website to fetch HTML from ...
$url = 'http://www.phpbb.com/index.php';
//Add user details if needs ...
$username = '';
$password = '';
// Add your own user-agent if you want ...
$user_agent = '';
$content = getContent( $url, $username, $password, $user_agent );
echo "<p>HTML-content from <i>" . $url . "</i>.<BR /><BR />" . $content . "</p>";
?>
Best regards,
mbrodin
Bookmarks