Advertisement
Trigub_Ilia

Авторизоваться через curl

Jan 21st, 2019
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <?php
  2. function request($url,$post = 0){
  3.     $ch = curl_init();
  4.     curl_setopt($ch, CURLOPT_URL, $url ); // отправляем на
  5.     curl_setopt($ch, CURLOPT_HEADER, 0); // пустые заголовки
  6.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // возвратить то что вернул сервер
  7.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // следовать за редиректами
  8.     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);// таймаут4
  9.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  10.     curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt'); // сохранять куки в файл
  11.     curl_setopt($ch, CURLOPT_COOKIEFILE,  dirname(__FILE__).'/cookie.txt');
  12.     curl_setopt($ch, CURLOPT_POST, $post!==0 ); // использовать данные в post
  13.     if($post)
  14.         curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  15.     $data = curl_exec($ch);
  16.     curl_close($ch);
  17.     return $data;
  18. }
  19.  
  20. $mdpu_dfn1 = request("http://www.dfn.mdpu.org.ua/login/index.php", array("username"=>"Логин","password"=>"Пароль","anchor"=>""));//Авторизуемся
  21. $mdpu_dfn2 = request("http://www.dfn.mdpu.org.ua/course/view.php?id=417", array());//Появляемся на курсе
  22. $mdpu_dfn2 = request("http://www.dfn.mdpu.org.ua/mod/chat/gui_ajax/index.php?id=19", array());//Появляемся в чате
  23.  
  24. echo "<pre>";
  25. print_r($mdpu_dfn2);
  26. echo "</pre>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement