2022-08-29
<?php
session_start();
$secret_word = 'medicaps university';
//create validate function here
?>
<?php
unset($username);
if ($_COOKIE['login'])
{
list($c_username,$cookie_hash) = preg_split(',',$_COOKIE['login']);
if (md5($c_username.$secret_word) == $cookie_hash)
{
$username = $c_username;
}
else
{
print "You have sent a bad cookie.";
}
}
if ($username)
{
print "Welcome, $username.";
}
else
{
print "Welcome, anonymous user.";
}
?>
<?php
if (isset($_SESSION['loggedInUser'])) {
?>
print('logged in HTML and code here');
<?php
}
else
{
if(isset($_POST['submit'])) {
if (validate($_REQUEST['username'],$_REQUEST['password']))
{
$cookie_name = "login";
$cookie_value = $_REQUEST['username'].','.md5($_REQUEST['username'].$secret_word);
setcookie($cookie_name,$cookie_value, time() + 1 * 24 * 60 * 60);
$_SESSION['loggedInUser'] = $_REQUEST['username'];
} else {
print('<br>error invalid user name or password');
}
} else {
print('<br>html form here');
}
}
?>