Skip to content

Commit 8bc0764

Browse files
feat: access jwt webtoken
1 parent fa230f7 commit 8bc0764

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

.htaccess

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
RewriteEngine on
22
RewriteRule ^([a-z]+)$ index.php?table=$1
3-
RewriteRule ^([a-z]+)/([0-9]+)$ index.php?table=$1&&id=$2
3+
RewriteRule ^([a-z]+)/access_token=([a-z0-9]+)$ index.php?table=$1&&access_token=$2
4+
RewriteRule ^([a-z]+)/([0-9]+)$ index.php?table=$1&&id=$2
5+
RewriteRule ^([a-z]+)/([0-9]+)/access_token=([a-z0-9]+)$ index.php?table=$1&&id=$2&&access_token=$3

env-simple.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
define('USER_NAME', '');
66
define('PASSWORD', '');
77
define('DATABASE_NAME', '');
8+
define('ACCESS_TOKEN', '');
89

910
?>

index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?php
22

3+
/* Include Varibles File */
4+
include 'env.php';
5+
36
/* Include View Files */
47
include 'views/header.view.php';
8+
include 'views/access_token.view.php';
59
include 'views/table.view.php';
610

711
/* Check ID */

views/access_token.view.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/* Check Access Token */
4+
if(isset($_GET['access_token'])) {
5+
6+
if ($_GET['access_token'] != ACCESS_TOKEN) {
7+
echo json_encode(array('status'=>'Fail', 'error'=>'Please provide valid access token'));
8+
die();
9+
}
10+
}
11+
12+
/* Check Authorization */
13+
else if (isset($headers['Authorization'])) {
14+
15+
if ($headers['Authorization'] != "Bearer ".ACCESS_TOKEN) {
16+
echo json_encode(array('status'=>'Fail', 'error'=>'Please provide valid access token'));
17+
die();
18+
}
19+
}
20+
21+
else {
22+
echo json_encode(array('status'=>'Fail', 'error'=>'Please provide access token'));
23+
die();
24+
}
25+
26+
?>

views/database.view.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22

3-
/* Include Varibles File */
4-
include 'env.php';
5-
63
/* Create connection */
74
$con = new mysqli(SERVER_NAME, USER_NAME, PASSWORD, DATABASE_NAME);
85

views/header.view.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
header("Content-Type: application/json; charset=UTF-8");
66
header("Access-Control-Allow-Methods: POST, GET, PUT, DELETE");
77
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
8+
$headers = getallheaders();
89

910
?>

0 commit comments

Comments
 (0)