Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save n1shantshrivastava/10018000 to your computer and use it in GitHub Desktop.
Save n1shantshrivastava/10018000 to your computer and use it in GitHub Desktop.
<?php
function http_file_get_contents( $url ) {
$response = file_get_contents( $url );
return $response;
}
?>
<?php
function http_fopen( $url ) {
$params = array(
'http' => array(
'method' => 'GET'
)
);
$ctx = stream_context_create($params);
$fp = @fopen( $url, 'rb', false, $ctx);
$response = '';
while( is_resource( $fp ) &&
$fp &&
!feof( $fp ) ) {
$response .= fread( $fp , 1024);
}
fclose($fp);
return $response;
}
?>
<?php
function http_fsockopen( $url )
{
$parts=parse_url($url);
$fp = fsockopen($parts['host'],
isset($parts['port'])?$parts['port']:80,
$errno, $errstr, 30);
$path = ( isset( $parts['path'] )? $parts['path'] : '/' );
$out = "GET ". $path ." HTTP/1.1\r\n";
$out.= "Host: ".$parts['host']."\r\n";
$out.= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$response = '';
while( is_resource( $fp ) &&
$fp &&
!feof( $fp ) ) {
$response .= fread( $fp , 1024);
}
fclose($fp);
return $response;
}
?>
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once( 'http_fopen.php' );
require_once( 'http_fsockopen.php' );
require_once( 'http_file_get_contents.php' );
$url = 'http://www.leggetter.co.uk';
// $response = http_fopen( $url );
$response = http_fsockopen( $url );
//$response = http_file_get_contents( $url );
echo( $response );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment