【问题标题】:Running on localhost but does not work on the server. (PHP cURL)在本地主机上运行,​​但在服务器上不起作用。 (PHP卷曲)
【发布时间】:2016-09-10 01:34:57
【问题描述】:

我在本地主机中收到了验证码,但同一代码服务器无法正常工作。我尝试使用 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);
?>

你能帮帮我吗?

【问题讨论】:

  • “不起作用”到底是什么意思?
  • 我的意思是,它在服务器上不起作用。
  • 是的,但无法正常工作,它会着火、冒烟、发出巨大的磨擦声还是出现 Rick Astley 视频?
  • 大多数情况下你应该把
  • 对不起@Richard,不幸的是,不再。 cookie.txt 不会以任何方式创建一个空白文件,即使它构成 cookie 文件也不会打印。

标签: php curl cookies server localhost


【解决方案1】:

这可能是一个安全问题。想象一下,攻击者可以更改您的 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");
}

【讨论】:

    猜你喜欢
    • 2019-05-08
    • 2013-04-28
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多