[英]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.