Skip to content

Instantly share code, notes, and snippets.

@NirmalAriyathilake
Created October 26, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NirmalAriyathilake/f88d463012a3fb8ede15a23e9eb1cf36 to your computer and use it in GitHub Desktop.
Save NirmalAriyathilake/f88d463012a3fb8ede15a23e9eb1cf36 to your computer and use it in GitHub Desktop.
Double Submit Cookies Pattern - logout.php
<?php
session_start();
//remove PHPSESSID from browser
if ( isset( $_COOKIE[session_name()] ) )
setcookie( session_name(), null, time()-3600, '/' );
//clear session from globals
$_SESSION = array();
//clear session from disk
session_destroy();
$cookieName = "sessionCookie";
if ( isset( $_COOKIE[$cookieName] ) )
setcookie($cookieName, null, time()-3600, '/');
$cookieNameCsrf = "csrfTokenCookie";
if ( isset( $_COOKIE[$cookieNameCsrf] ) )
setcookie($cookieNameCsrf, null, time()-3600, '/');
?>
<html>
<body>
<script>
alert("You are Successfully Logged out!");
window.location.href = "index.php";
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment