爲什麼我得到這個錯誤:爲什麼這些函數不能看到我的變量?
Undefined variable key_2captcha
我運行此代碼到一個CAPTCHA傳遞給2captcha服務器:
<?php
$id_Captcha=0;
$key_2captcha="key2captcha";
function send_captcha($base_file){
$ch = curl_init("http://2captcha.com/in.php");
curl_setopt($ch, CURLOPT_POSTFIELDS,
array('method'=>"base64",
'key'=>$key_2captcha,
'numeric'=>1,
'max_len'=>1,
'body'=>$base_file,
'submit'=>'download and get the ID'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
curl_close($ch);
return $postResult;
}
function getSolveCaptcha($id_captcha){
$c = curl_init("http://2captcha.com/res.php?key=".$key_2captcha."&action=get&id=".$id_captcha);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($c);
curl_close($c);
return $postResult;
}
?>
我運行XAMPP這個代碼。
值得指出的是,當然,前提是'global'變量幾乎都是錯誤的解決方案。跟蹤你可以使用什麼,並確保你不會破壞全球狀態,可能會很複雜。 – halfer 2015-04-01 16:00:55