-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsession_destroy.php
96 lines (94 loc) · 3.32 KB
/
session_destroy.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
<?php
namespace ZainPrePend\Session;
function SessionDestroyOnRequest()
{
if (!empty($_GET['session_destroy'])) {
if (!session_id()) {
session_start();
}
session_destroy();
$params = session_get_cookie_params();
setcookie(session_name(), '', 0, $params['path'], $params['domain'], $params['secure'], isset($params['httponly']));
$cookiNameList = array();
$domainList = getDomainList();
if (isset($_SERVER['HTTP_COOKIE'])) {
$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
foreach ($cookies as $cookie) {
$parts = explode('=', $cookie);
$name = trim($parts[0]);
if (in_array($name,array('XDEBUG_SESSION','adminhtml'))) {
continue;
}
$cookiNameList[] = $name;
deleteCookie($name);
}
}
$contents = ob_get_contents();
if ($contents) {
echo "<br/> has contents File:" . __FILE__ . " line:" . __LINE__ . "<br/>\r\n";
}
if (empty($cookies)) {
echo "<br/> no cookies found File:" . __FILE__ . " line:" . __LINE__ . "<br/>\r\n";
}
else {
\ZainPrePend\lib\T::printr($cookies, 'cookies');
\ZainPrePend\lib\T::printr($cookiNameList, 'cookie names');
\ZainPrePend\lib\T::printr($domainList, 'domain list');
}
echo "<br/> destroyed your session File:" . __FILE__ . " line:" . __LINE__ . "<br/>\r\n";
die;
}
}
function SessionInfoDestroyInline()
{
$aRemoveCookie = array('frontend');
foreach ($_COOKIE as $vKey => $vValue) {
if (in_array($vKey,$aRemoveCookie)){
unset($_COOKIE[$vKey]);
deleteCookie($vKey);
}
}
$aCookie = explode(';', $_SERVER['HTTP_COOKIE']);
$aKeepCookie = array();
foreach ($aCookie as $vCookie) {
$aParts = explode('=', $vCookie);
$vName = trim($aParts[0]);
if (!in_array($vName,$aRemoveCookie)) {
$aKeepCookie[] = $vCookie;
}
}
$vKeepCookie = implode(';',$aKeepCookie);
$_SERVER['HTTP_COOKIE'] = $vKeepCookie;
}
function deleteCookie($vCookieName)
{
setcookie($vCookieName, '', time() - 1000);
setcookie($vCookieName, '', time() - 1000, '/');
$aDomainList = getDomainList();
foreach ($aDomainList as $vDomain) {
setcookie($vCookieName, '', time() - 1000, null, $vDomain);
setcookie($vCookieName, '', time() - 1000, '/', $vDomain);
setcookie($vCookieName, '', time() - 1000, null, '.' . $vDomain);
setcookie($vCookieName, '', time() - 1000, '/', '.' . $vDomain);
}
}
function getDomainList()
{
static $aDomainList;
if (is_null($aDomainList)){
$aDomainList = array();
if (isset($_SERVER["HTTP_HOST"])) {
$primaryDomain = $_SERVER["HTTP_HOST"];
$firstDomain = ltrim($primaryDomain, '.');
$domainParts = explode('.', $firstDomain);
unset($domainParts[0]);
$parentDomain = implode('.', $domainParts);
$aDomainList[] = $firstDomain;
$aDomainList[] = '.' . $firstDomain;
$aDomainList[] = $parentDomain;
$aDomainList[] = '.' . $parentDomain;
}
}
return $aDomainList;
}
SessionDestroyOnRequest();