Advertisement
Artem78

Untitled

Sep 25th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?php
  2.     header('Control-Allow-Origin: *');
  3.     header('Access-Control-Allow-Origin: *');
  4.  
  5.     $url = 'http://www.russianpost.ru/autotarif/Autotarif.aspx';
  6.     $params = '?viewPost=26&countryCode=643&typePost=1';
  7.     $params .= '&weight=' . $_GET['weight'];
  8.     $params .= '&value1=' . $_GET['value1'];
  9.     $params .= '&postOfficeId=' . $_GET['postOfficeId'];
  10.     $html = file_get_contents($url.$params);
  11.    
  12.     preg_match('/<input id="key" name="key" value="([0-9]+)"\/>/', $html, $matches);
  13.     if ($matches) {
  14.         $context = stream_context_create(array(
  15.             'http' => array(
  16.                 'method' => 'POST',
  17.                 'header' => 'Content-Type: application/x-www-form-urlencoded' . PHP_EOL,
  18.                 'content' => 'key=' . $matches[1],
  19.             ),
  20.         ));
  21.        
  22.         $html = file_get_contents($url, false, $context);
  23.     }
  24.  
  25.     preg_match('/<span id="lblErrStr">(.*)<\/span>/', $html, $error);
  26.     if (!empty($error[1])) {
  27.         echo $error[1];
  28.     } else {
  29.         preg_match('/<span id="TarifValue">([0-9,]+)<\/span>/', $html, $result);
  30.         echo str_replace(',', '.', $result[1]);
  31.     }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement