为什么我得到这个错误:为什么这些函数不能看到我的变量?
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