-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCookiesHelper.php
98 lines (85 loc) · 2.56 KB
/
CookiesHelper.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
//namespace App\Http\Controllers\Api\Web;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Http\Request;
class CookiesController extends Controller
{
/**
* Create a Encrypted Cookie.
* By Default Laravel uses and works with Encrypted Cookies.
*
* @param \Illuminate\Http\Request $request
* @return null
* @important name, token, expires
*/
public function Encrypted(Request $request)
{
$name = $request->name;
$value = $request->value;
$expires = time() + (86400 * ($request->expires));
$path = "/api/cookies/";
$domain = "";
$secure = false;
$httponly = true;
setrawcookie($name, $value, $expires, $path, $domain, $secure, $httponly);
}
/**
* Create a Unencrypted Cookie.
*
* @param \Illuminate\Http\Request $request
* @return null
* @important name, token, expires
*/
public function Unencrypted(Request $request)
{
$name = $request->name;
$token = $request->token;
$expires = time() + (86400 * ($request->expires));
$path = "/api/cookies/";
$domain = "";
$secure = false;
$httponly = false;
setrawcookie($name, $token, $expires, $path, $domain, $secure, $httponly);
}
/**
* Retreive a Cookie value.
*
* @param string $name
* @return \Illuminate\Http\JsonResponse
*/
public function Retrieve(string $name)
{
$value = Cookie::get($name);
if (is_null($value)) {
return response()->json(['response' => 'No Records!'], 404);
}
return response()->json($value, 200);
}
/**
* Delete a Cookie.
*
* @param string $name
* @return null
*/
public function Remove(string $name)
{
//set the expiration date to 12 hour ago
$expires = time() - 43200;
$path = "/api/cookies/";
$domain = "";
$secure = false;
$httponly = true;
setrawcookie($name, "", $expires, $path, $domain, $secure, $httponly);
}
/**
* Retreive a specific value from a existing Cookie.
*
* @param string $name
* @return \Illuminate\Http\JsonResponse
*/
public function Check(string $name)
{
return Cookie::has($name) ? response()->json(['response' => 'false'], 404) : response()->json(['response' => 'true'], 200);
}
}