开发者

php fopen disabled - alternative needed

开发者 https://www.devze.com 2022-12-10 16:02 出处:网络
My web host just disabled fopen() M开发者_StackOverflowy script used to open and write to a text file on the server, but no longer can.

My web host just disabled fopen()

M开发者_StackOverflowy script used to open and write to a text file on the server, but no longer can.

Is there an alternative function to fopen?


You might be able to do it with fsockopen(). For me this worked:

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

Don't forget to change the host and request parameter


Not that I know of. But it's a perfectly safe function to use on shared hosting (BUT ONLY IF the environment is set up right), so if your host disabled it for security reasons they're security noobs and you should find a new host.

Find a new one anyways


I don't think cURL requires allow_url_fopen to be enabled. However, the cURL extension must be installed. Use phpinfo() to check if it's installed.

It's a little more advanced than your normal fopen() or file_get_contents() but it's definitely an alternative.


If it's available you could probably replicate your script with cURL

http://us3.php.net/cURL

0

精彩评论

暂无评论...
验证码 换一张
取 消