0

我将表单提交到一个 URL 并使用 cURL 从另一个 URL 接收数据。但是,我无法收到收到警报的数据您的网络会话已过期,因为 20 分钟内没有任何活动。请点击这里重新开始。有任何想法吗 ?谢谢。代码如下:

获取内容.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Get Document</title>
 </head>
 <body>
   <?php
     $urlpost = 'https://ameliaweb5.intelisys.ca/VietJet/ViewFlights.aspx';
     $urlget = 'https://ameliaweb5.intelisys.ca/Vietjet/TravelOptions.aspx?lang=en&st=pb&sesid=';
     $gethtml = inputInfo($urlpost, $urlget);

     function inputInfo($urlpost, $urlget) {
      $result = setInfo($urlpost, $urlget);
      echo $result;
     }

     function setInfo($urlpost, $urlget) {
      if(isset($_POST['roundtrip']))   $roundtrip       = $_POST['roundtrip'];
      if(isset($_POST['origin']))      $originhtml      = $_POST['origin'];
      if(isset($_POST['destination'])) $destinationhtml = $_POST['destination'];
      if(isset($_POST['departdate']))  $departdate      = $_POST['departdate'];
      if(isset($_POST['returndate']))  $returndate      = $_POST['returndate'];
      if(isset($_POST['adults']))      $adults          = $_POST['adults'];
      if(isset($_POST['children']))    $children        = $_POST['children'];
      if(isset($_POST['infants']))     $infants         = $_POST['infants'];

      switch($originhtml) {
       case 1: $origin = 'SGN';
        break;
       case 2: $origin = 'HAN';
        break;
      }

      switch($destinationhtml) {
       case 1: $destination = 'SGN';
        break;
       case 2: $destination = 'HAN';
        break;
      }

      $wannasay = array (
       "chkRoundTrip" => $roundtrip,
       "lstOrigAP" => $origin,
       "lstDestAP" => $destination,
       "departure1" => $departdate,
       "departure2" => $returndate,
       "lstLvlService" => 1,
       "lstResCurrency" => 'VND',
       "txtNumAdults" => $adults,
       "txtNumChildren" => $children,
       "txtNumInfants" => $infants
      );

      $dataels = '';
      foreach ($wannasay as $thiskey => $thisvalue) {
       $dataels .= $thiskey . '=' . $thisvalue . '&';   
      }

      rtrim($dataels, '&');

      $code = post_data($urlpost, $urlget, $dataels); 
      return $code;
     }

     function post_data($urlpost, $urlget, $dataels) {
      if(function_exists('curl_init')) {
       $timeout = 30;
       //   $cookie="cookie.txt";
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $urlpost);
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
       curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0)");
       curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
       curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       //   curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
       //   curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
       curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
       curl_setopt($ch, CURLOPT_POST, 1);
       curl_setopt($ch, CURLOPT_POSTFIELDS, $dataels);  
       curl_exec($ch);

       curl_setopt($ch, CURLOPT_URL, $urlget);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($ch, CURLOPT_HEADER, 0);
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

       $data = curl_exec($ch);
       curl_close($ch);

       return $data;
      }else {
       return 0;
     }
    }
  ?>
  </body>
</html>

获取内容.html

html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>get content</title>
 </head>
 <body>
  <form name="searchticket" action="getcontent.php" method="post">
   <div class="content-flight">
    <div class="radio">
     <input id="roundtrip" type="radio" name="roundtrip" value="RbRoundTrip" checked="checked" />
     <label for="roundtrip">Round Trip</label>
     <input id="rboneway" type="radio" name="roundtrip" value="RbOneWay" />
     <label for="rboneway">One Way</label>
    </div><!--radio-->
    <div class="clear"></div>
    <table>
     <tr>
      <td>Origin
       <select id="origin" name="origin">
        <option value="0">Origin</option>
        <option value="1">Tp. Hồ Chí Minh</option>
        <option value="2">Hà Nội</option>
       </select>
      </td>
      <td>
       <input name="departdate" type="text" value="08/06/2013" id="DepartDate" title="Depart Date" />
      </td>
     </tr>
    </table>
    <table>
     <tr>
      <td>Destination
       <select id="destination" name="destination">
        <option value="0">Destination</option>
        <option value="1">Tp. Hồ Chí Minh</option>
        <option value="2">Hà Nội</option>
       </select>
      </td>
      <td>
       <input name="returndate" type="text" value="10/06/2013" id="ReturnDate" title="Return Date"  />
      </td>
     </tr>
    </table>
    <table>
     <tr>
      <td>Adults
       <select id="adults" name="adults">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
       </select>
      </td>
      <td> >= 12 Ages</td>
     </tr>
    </table>
    <table>
     <tr>
      <td>Children
       <select id="children" name="children">
        <option value="0">0</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
       </select>
      </td>
      <td> 2 - 11 Ages</td>
     </tr>
    </table>
    <table>
     <tr>
      <td>Infants
       <select id="infants" name="infants">
        <option value="0">0</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
       </select>
      </td>
      <td> < 24 moths</td>
     </tr>
    </table>
    <div class="clear"></div>
    <div>
     <input type="submit" value="Search Ticket"/>
    </div>
   </div>
  </form>
 </body>
</html>
4

0 回答 0