Usage: (this one's PHP5.x only) because of the use of the stream context;
<?php
function _getfile($url)
{
ini_set('error_reporting', E_ALL);
$false = 0;
exec("/sbin/ifconfig", $ips);
$regex = "@addr\:((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))@";
$ipstr = implode( $ips );
$ipstr = preg_replace( "@127\.0\.0\.1@", "", $ipstr ); // Don't want localhost
preg_match_all( $regex, $ipstr, $matches );
$opts = array( 'socket' =>
array( 'bindto' => $matches[1][array_rand( $matches[1] )].':0' ) );
$context = stream_context_create($opts);
results = file_get_contents( $url, $false, $context );
return results;
}
?>
This one's PHP4.x+;
<?php
function _getfile($url)
{
exec("/sbin/ifconfig", $ips);
$regex = "@addr\:((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))@";
$ipstr = implode( $ips );
$ipstr = preg_replace( "@127\.0\.0\.1@", "", $ipstr ); // Don't want localhost
preg_match_all( $regex, $ipstr, $matches );
$URI_PARTS = parse_url( $url );
$sock = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
socket_bind ( $sock, $matches[1][array_rand( $matches[1] )] );
$ip = gethostbyname( $URI_PARTS['host'] );
socket_connect ( $sock, $ip, 80 );
$request = 'GET '.$URI_PARTS['path'].'?'.$URI_PARTS['query']." HTTP/1.1\n".
'Host: '.$URI_PARTS['host']."\n\n";
socket_write( $sock, $request );
$results = '';
while( $buffer = @socket_read( $sock, 512 ,PHP_NORMAL_READ ) )
$results .= $buffer;
socket_close( $sock );
return $results;
}
?>