curl命令在php

时间:2017-05-29 07:18:28

标签: php curl

php curl中是否有任何命令可以打印响应查询字符串参数

以下是我的PHP代码

      <?php
      session_start();

      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL,"http://192.168.1.220/cgi-bin/handle_login.tcl");
     curl_setopt($ch, CURLOPT_POST, TRUE);
     curl_setopt($ch, CURLOPT_POSTFIELDS,
        "user=admin&pw=admin&submit=Login&sid=' '");        
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: x-www-form-urlencoded'));

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
     $response = curl_exec($ch);
     echo "$response";
     curl_close ($ch);
  ?>

以下是标题回复

      Request URL:http://localhost:8080/cgi-bin/frameset.tcl?
      sid=3514275041172666092
      Request Method:GET
      Status Code:404 Not Found
      Remote Address:[::1]:8080
      Referrer Policy:no-referrer-when-downgrade

响应标题

    Accept-Ranges:bytes
    Connection:Keep-Alive
    Content-Language:en
    Content-Type:text/html; charset=utf-8
    Date:Mon, 29 May 2017 06:54:33 GMT
    Keep-Alive:timeout=5, max=99
    Server:Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.4
    Transfer-Encoding:chunked
    Vary:accept-language,accept-charset

请求标题

  Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,
         */*;q=0.8
  Accept-Encoding:gzip, deflate, sdch, br
  Accept-Language:en-US,en;q=0.8
  Connection:keep-alive
  Cookie:PHPSESSID=hj7kbp4hp0pjq16m1tk7j3goo3; _ga=GA1.1.981975196.1489736033; XDEBUG_TRACE=XDEBUG_ECLIPSE
  DNT:1
  Host:localhost:8080
  Referer:http://localhost:8080/nias/automate.php
  Upgrade-Insecure-Requests:1
  User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

查询字符串参数

    sid=3514275041172666092 //need to print these value

1 个答案:

答案 0 :(得分:0)

由于输出是字符串格式,输出每次都保持不变..需要找到字符串中所需字符的位置并提取所需的值..

以下是代码

           $response= curl_exec($ch);//executes the curl
           echo strpos("$response","variable_to_find")."<br/>";//know the position
           $sid = substr($response,position,length);