2016-05-13 18:30
浏览 217

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

I received an captcha in my localhost but the same code server does not work. I try to run my own server with chmod full authority also gave full authority in the cookie.txt file. When I run the perfect localhost. I think, it does not work because of cookie.txt

    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: Gecko/20070219 Firefox/');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_COOKIE, 1);
            if($cookie != ""){
                    curl_setopt($ch, CURLOPT_COOKIEJAR, realpath(dirname(__FILE__))."\cookie.txt");
                    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, "");
    $result = curl_exec($ch); 
    return $result;
    open("", 1);
    echo open("".(floor(rand() * 1000) + 1), 0);

Can you help me Please?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duangang2825 2016-05-14 06:45

    It's probably a security issue. Imagine that an attacker could change your php files and take over your application. That's why Apache server is running under user www-data, which doesn't have access to your files other than read-only. The same applies for directories.

    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");
    解决 无用
    打赏 举报

相关推荐 更多相似问题