php - Why can't these functions see my variable? -


why error:

undefined variable key_2captcha

i run code pass captcha 2captcha server:

<?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 , 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; } ?> 

i run code in xampp.

use below code use $key_2captcha global. in both function. read variable scope in php

function getsolvecaptcha($id_captcha){   global $key_2captcha;    $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; } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -