Skip to content

Instantly share code, notes, and snippets.

@elgamine-dev
Created May 30, 2016 09:57
Show Gist options
  • Save elgamine-dev/4e231252ef32e0bf6c6aa9ec02f83449 to your computer and use it in GitHub Desktop.
Save elgamine-dev/4e231252ef32e0bf6c6aa9ec02f83449 to your computer and use it in GitHub Desktop.
<?php
session_start();
if(isset($_POST['msg'])) {
$_SESSION['msg'] = htmlspecialchars($_POST['msg']);
}
if(isset($_GET['logout'])) {
session_destroy();
}
function flash(){
if(isset($_SESSION['msg'])) {
$msg = $_SESSION['msg'];
unset($_SESSION['msg']);
}
return $msg;
}
?><!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/components/message.css">
<!-- Place favicon.ico in the root directory -->
<style>
body {
font-size:22px;
}
</style>
</head>
<body>
<?php if(isset($_SESSION['msg'])) : ?>
<div class="ui message"><?=flash()?></div>
<?php endif; ?>
<h1>session !</h1>
<form action="?" method="post">
<input type="text" name="msg">
<button>go</button>
</form>
<a href="?logout">Logout</a>
<details>
<h3>Session</h3>
<pre><code><?php var_dump($_SESSION)?></code></pre>
<h3>Cookie</h3>
<pre><code><?php var_dump($_COOKIE)?></code></pre>
</details>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment