/
login.php
39 lines (33 loc) · 879 Bytes
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/*Login verfication for website*/
ini_set('display_errors', 1);
session_start();
if(isset($_POST['user']))
$user = htmlspecialchars($_POST['user']);
if(isset($_POST['password']))
$password = htmlspecialchars($_POST['password']);
if(isset($user) && isset($password)){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://web.engr.oregonstate.edu/~pfisterl/cs419/token.php',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
grant_type => 'client_credentials'
),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERPWD => "{$user}:{$password}"
));
$resp = curl_exec($curl);
$resp = json_decode($resp);
$access_token = $resp->{'access_token'};
/*Store token in session*/
$_SESSION['token'] = $access_token;
curl_close($curl);
}
else{
http_response_code(404);
exit(1);
}
session_close();
exit();
?>