
How to create a login page in php?

<?php
session_start();
if(!isset($_SESSION['nameofsession'])){
$_SESSION['nameofsession'] = 0;
}
if($_SESSION['nameofsession'] != 0) {
header('Refresh: targetPage');
} else {
if(isset($_REQUEST['submit'])){
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
//authenticate somehow!
}
?>
<!doctype html>
<html>
<head>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Username: <input type="text" name="username" value="" /><br />
Password: <input type="password" name="password" value="" /><br />
<input type="submit" name="submit" value="Login" /><br />
</form>
</body>
<?php
}
exit;
?>

<?php
session_start();
if(!isset($_SESSION['nameofsession'])){
$_SESSION['nameofsession'] = 0;
}
if($_SESSION['nameofsession'] != 0) {
header('Refresh: targetPage');
} else {
if(isset($_REQUEST['submit'])){
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
//authenticate somehow!
//if authentication succeeded:
$_SESSION['nameofsession'] = 1;
header('Refresh: targetPage');
}
?>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
Username: <input type="text" name="username" value=""><br />
Password: <input type="password" name="password" value=""><br />
<input type="submit" name="submit" value="Login"><br />
</form>
<?php
}
exit;
?>