2014-02-28 59 views
-2

我想通过Ajax函数发送函数中的cUrl请求。通过ajax发送cUrl函数中的函数参数

这是我cUrl作者请求:

function cUrlConnection ($url, $username, $password, $ch) { 

     $pass = md5($password); 

     $data = array( 
      'username' => $username, 
      'password'=> $pass, 

     ); 

     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; pl; rv:1.8.0.4) Gecko/20060426 Firefox/1.5.0.4'); 
     curl_setopt($ch, CURLOPT_TIMEOUT, '40'); 
     curl_setopt($ch, CURLOPT_POST, 1); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
     curl_setopt($ch, CURLOPT_HEADER, 0); 

     $result = curl_exec($ch); 

     $pos = strpos($result, "התחברת בהצלחה"); 

     if ($pos === false) { 
      return false; 
     } 
     else 
     { 
      return $ch; 
     } 
    } 
$chs = cUrlConnection($url, $username, $password, $ch); 

我想与函数发送变量$ CHS,通过Ajax的另一个文件。 我该怎么做?

+0

请在启动$ CH = curl_init($网址)的使用;你还没有初始化$ ch –

+0

这是正确的,我添加了这个,但在这里我隐藏它。 –

回答

0

改变这种(使用数组这样使得多形式发布):

curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 

到:

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));