Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.17 KB | None | 0 0
  1. <?php
  2. $ba_login = 'asd';
  3. $ba_password = 'asdasd';
  4.  
  5. $ba_user_agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36';
  6.  
  7. // заголовки для главной страницы
  8. $ba_get_main_headers = array(
  9.  'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
  10.  'Upgrade-Insecure-Requests: 1',
  11.  'Accept-Encoding: gzip, deflate, sdch',
  12.  'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4',
  13.  'Connection: keep-alive',
  14.  'Host: www.britishairways.com',
  15.  'User-Agent: '.$ba_user_agent,
  16. );
  17.  
  18. // получаем cookies с главной страницы сайта
  19. $ba_get_main = post('http://www.britishairways.com/travel/home/public/ru_ru', array(
  20.  'headers' => $ba_get_main_headers,
  21.  'cookies' => 'Allow_BA_Cookies=accepted; BA_COUNTRY_CHOICE_COOKIE=RU; BA_LANGUAGE_CHOICE_COOKIE=RU'
  22. ));
  23.  
  24. preg_match('/name\="eId" value\="(.*?)"/isu', $ba_get_main_content_result, $ba_eId);
  25.  
  26. // заголовки для авторизации
  27. $ba_user_auth_headers = array(
  28.  'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
  29.  'Accept-Encoding: gzip, deflate',
  30.  'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4',
  31.  'Content-Length: 83',
  32.  'Content-Type: application/x-www-form-urlencoded',
  33.  'Connection: keep-alive',
  34.  'Host: www.britishairways.com',
  35.  'Origin: http://www.britishairways.com',
  36.  'Referer: http://www.britishairways.com/travel/home/public/ru_ru',
  37.  'Upgrade-Insecure-Requests: 1',
  38.  'User-Agent: '.$ba_user_agent
  39. );
  40.  
  41. // авторизация
  42. $ba_user_auth = post('https://www.britishairways.com/travel/loginr/public/ru_ru', array(
  43.  'headers' => $ba_user_auth_headers,
  44.  'params' => 'Directional_Login=&eId='.$ba_eId[1].'&source=headerbtn&password='.$ba_password.'&membershipNumber='.urlencode($ba_login),
  45.  'cookies' => $ba_get_main['cookies'].'; Allow_BA_Cookies=accepted; BA_COUNTRY_CHOICE_COOKIE=RU; BA_LANGUAGE_CHOICE_COOKIE=RU'
  46. ));
  47.  
  48. echo baFilesUrlReplace(gzdecode($ba_user_auth['content']));
  49.  
  50. function printR($array = null) {
  51.  echo '<pre>';
  52.  print_r($array);
  53.  echo '</pre>';
  54. }
  55.  
  56. function baFilesUrlReplace($content = null) {
  57.  return preg_replace('/\/cms\/global\/styles\//isu', 'https://www.britishairways.com/cms/global/styles/', $content);
  58. }
  59.  
  60. function post($url = null, $params = null) {
  61.  $ch = curl_init();
  62.  
  63.  curl_setopt($ch, CURLOPT_URL, $url);
  64.  curl_setopt($ch, CURLOPT_HEADER, 1);
  65.  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  66.  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  67.  
  68.  if(isset($params['params'])) {
  69.   curl_setopt($ch, CURLOPT_POST, 1);
  70.   curl_setopt($ch, CURLOPT_POSTFIELDS, $params['params']);
  71.  }
  72.  
  73.  if(isset($params['headers'])) {
  74.   curl_setopt($ch, CURLOPT_HTTPHEADER, $params['headers']);
  75.  }
  76.  
  77.  if(isset($params['cookies'])) {
  78.   curl_setopt($ch, CURLOPT_COOKIE, $params['cookies']);
  79.  }
  80.  
  81.  $result = curl_exec($ch);
  82.  
  83.  list($headers, $result) = explode("\r\n\r\n", $result, 4);
  84.  
  85.  preg_match_all('|Set-Cookie: (.*);|U', $headers, $parse_cookies);
  86.  
  87.  $cookies = implode(';', $parse_cookies[1]);
  88.  
  89.  curl_close($ch);
  90.  
  91.  return array('headers' => $headers, 'cookies' => $cookies, 'content' => $result);
  92. }
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement