maprangsoft

ตัวอย่างให้น้อง

Aug 5th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. <?php
  2.  
  3. //in Route:
  4.  
  5. Route::post('/testAuthen', 'LoginController@login');
  6.  
  7.  
  8. //in Controller:
  9.     private function authenticate( $username, $password ) {
  10.  
  11.         $post_data = http_build_query(
  12.                 array(
  13.                         'url' => 'its2.cgi.ac.th',
  14.                         'username' => $username,
  15.                         'password' => $password
  16.                 )
  17.         );
  18.  
  19.         $opts = array(
  20.                 'http' => array(
  21.                         'method'  => 'POST',
  22.                         'header'  => 'Content-type: application/x-www-form-urlencoded',
  23.                         'content' => $post_data
  24.                 )
  25.         );
  26.  
  27.         $context  = stream_context_create( $opts );
  28.         $result = file_get_contents( self::AUTHEN_USER_URL, false, $context );
  29.  
  30.         $result_arr = json_decode( $result, true );
  31.  
  32.         return json_decode( $result, true );
  33.     }
  34.  
  35.     public function login(Request $request)
  36.     {
  37.         echo $this->authenticate('natthawut', 'password');
  38.     }
  39.  
Add Comment
Please, Sign In to add comment