繁体   English   中英

在localhost上运行,但在服务器上不起作用。 (PHP cURL)

[英]Running on localhost but does not work on the server. (PHP cURL)

我在本地主机中收到了一个验证码,但同一代码服务器无法正常工作。 我尝试使用chmod完全权限运行我自己的服务器,并且在cookie.txt文件中也赋予了完全权限。 当我运行完美的本地主机时。 我认为,由于cookie.txt,它不起作用

<?php
    header("Content-type: image/jpeg");
function open($url, $cookie = "")
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_COOKIE, 1);
            if($cookie != ""){
                    curl_setopt($ch, CURLOPT_COOKIEJAR, realpath(dirname(__FILE__))."\cookie.txt");
            }else{
                    curl_setopt($ch, CURLOPT_COOKIEFILE, realpath(dirname(__FILE__))."\cookie.txt");
            }
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, "http://www.xxxxxx.com/caller/");
    $result = curl_exec($ch); 
    curl_close($ch);
    return $result;
}
    open("http://www.xxxxxx.com/caller/", 1);
    echo open("http://www.xxxxxx.com/security.php?id=".(floor(rand() * 1000) + 1), 0);
?>

你能帮我吗?

这可能是一个安全问题。 想象一下,攻击者可能会更改您的php文件并接管您的应用程序。 这就是Apache服务器在用户www-data下运行的原因,该用户只能以只读方式访问您的文件。 目录也是如此。

if($cookie != "") {
                curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/some_better_name_cookie.txt");
} else {
                curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/some_better_name_cookie.txt");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM