Created
October 7, 2012 16:20
-
-
Save recck/3848801 to your computer and use it in GitHub Desktop.
Programming in PHP - Week 6 - Day 11 - Sessions and Cookies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
if(isset($_POST['submit'])){ | |
if(isset($_POST['end'])){ | |
unset($_SESSION['yourName']); | |
header("Location: sessions.php"); | |
} | |
if(!empty($_POST['name'])){ | |
$_SESSION['yourName'] = htmlentities($_POST['name']); | |
}else { | |
echo 'Please enter a name!<br />'; | |
} | |
} | |
if(!empty($_SESSION['yourName'])){ | |
echo 'Welcome, ' . $_SESSION['yourName']; | |
}else { | |
echo 'Enter your name:'; | |
} | |
?><br /> | |
<form method="post"> | |
Name: <input type="text" name="name" /><br /> | |
End session? <input type="checkbox" name="end" value="1" /> | |
<input type="submit" name="submit" value="Submit" /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment