File_get_contents () is disabled for my own site

I am trying to connect to my own site using both CURL and the PHP file_get_contents () function to get the source of my webpage without success. I am running a PHP script on the same server from which I am trying to get the HTML source code. CURL does not return any errors, even when using curl_error (), and the PHP function file_get_contents () returns the following:

Warning: file_get_contents ([sitename]) [function.file-get-contents]: stream could not be opened: connection refused in [file path] on line 19.

I do not know why this is so. Why is the server actively refusing this connection? How can I stop him?

thank

EDIT:

For reference, here is my (cURL) code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.mydomain.co.uk');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, '');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.mydomain.co.uk')); 

$rawHTML = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);

print $err;
print 'HTML: ' . $rawHTML;
+6
8

, . ,

telnet localhost 80

? localhost, ip . , curl/php.

: ok, localhost , file_get_contents("http://localhost/");.

, localhost, Host:, . cURL, :

curl_setopt(CURLOPT_HTTPHEADER,array('Host: yourdomain.com'));

URL http://127.0.0.1/. , , .

edit ^ 2: cURL, :

$ip = '127.0.0.1';
$fp = fsockopen($ip, 80, $errno, $errstr, 5);
$result = '';
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.exampl.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        $result .= fgets($fp, 128);
    }
    fclose($fp);
}

( php.net)

+9

, , IP-, , , IP-, mvds.

www.domain.com = 234.234.234.234

server ip: 10.0.0.1

234.234.234.234 -> 10.0.0.1 , .

, IP localhost (127.0.0.1), (www.domain.com).

:

  • IP- . , , . , , , .

  • www.domain.com β†’ 127.0.0.1 hosts

  • - "" , localhost. PHP , mvds .

  • . , ? http ...

+5

, hosts (/etc/hosts)

127.0.0.1 example.com www.example.com

jishi!:)

+4

, , . / ?

, cURL PHP.

<?php

// Show all information
phpinfo();

?>

, , , fopen:

$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 5);
fclose($fh);
echo $theData;

http://php.net/manual/en/function.fopen.php

0

, allow_url_fopen php.ini.

0

, , .htaccess? , , PHP , . , , , .

0

- .

file_get_contents('/home/usr/public_html/path/page.html');

, .

"/usr/" .

, script , :

file_get_contents('page.html');
0

A very simple site where we can download the sad status of Punjabi on WhatsApp . By category, this is the best site, because there is a wide category of status

0
source

All Articles