<?
 
 $settings['cookiefile'] = "cookies.tmp";
 $aaa="";
     try {
            global $settings;
    
    
         } catch (Exception $e) {
                 die("FAILED: " . $e->getMessage());
  }
 function httpRequest($url, $post="") {
         global $settings;         $ch = curl_init();
         //Change the user agent below suitably
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');
 curl_setopt($ch, CURLOPT_URL, ($url));
         curl_setopt( $ch, CURLOPT_ENCODING, "UTF-8" );
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt ($ch, CURLOPT_COOKIEFILE, $settings['cookiefile']);
         if (!empty($post)) curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
  curl_setopt ($ch, CURLOPT_COOKIEJAR, $settings['cookiefile']);
         //UNCOMMENT TO DEBUG TO output.tmp
         //curl_setopt($ch, CURLOPT_VERBOSE, true); // Display communication with server
         //$fp = fopen("output.tmp", "w");
         //curl_setopt($ch, CURLOPT_STDERR, $fp); // Display communication with server         $xml = curl_exec($ch);

         if (!$xml) {
                 throw new Exception("Error getting data from server ($url): " . curl_error($ch));
         }         curl_close($ch);
        
         return $xml;
 }
function post($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec($ch);
}
 
 $xml = simplexml_load_string(httpRequest('http://127.0.0.1/api.php?action=login&format=xml','action=login&lgname=admin&lgpassword=asdqwe'));
 $expr = "/api/login[@token]";
 $result = $xml->xpath($expr);
 print_r($result);
 echo $aaa= $result[0]->attributes()->token; 
 $url2="http://127.0.0.1/api.php?action=login&lgname=admin&lgpassword=asdqwe&lgtoken=".$aaa;
 echo $url2;
post($url2);
 ?>
  <form action="http://127.0.0.1/api.php?action=login&format=xml&lgname=admin&lgpassword=asdqwe" method="post">
<input type="submit" value="登录" />
</form> $xml = simplexml_load_string(httpRequest('http://127.0.0.1/api.php?action=login&format=xml','action=login&lgname=admin&lgpassword=asdqwe'));执行这个函数 得到的 
文件流 和
同页面 <form post 的为什么不一样呢 本以为是写入COOKIES 的事结果 把那个删除仍旧不一样  CURL POST 执行  和FORM 返回的结果不同吗还有一个问题 function post() 函数 执行post 如何让他直接 post到  目标网址 直接转向到那里 这里不需要提交input只是 衔接以POST 方法传到目标地址@!