在localhost上运行,但在服务器上不工作。 (PHP cURL) [英] Running on localhost but does not work on the server. (PHP cURL)
问题描述
我在localhost中收到了验证码,但是同一个代码服务器不工作。我尝试运行我自己的服务器与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);
}
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
<?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);
?>
Can you help me Please?
解决方案 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");
}
这篇关于在localhost上运行,但在服务器上不工作。 (PHP cURL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!