Form: Authentication , isset &  empty,  together

 

Step: 1 Code

Client side

<html>
<title>form: empty_isset_both.htm </title>
<body text="#000080" bgcolor="#F7F0D7">
Determines if a variable is set and is not NULL.
<table border="1" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111" width="320">
<tr>
<td width="320">Please enter your name</td>
</tr>
<tr>
<td >
<form method="POST" action="empty_isset_both.php">
<input type="text" name="fname" size="40"><br>
<input type='hidden' name='insert_1' id='in_post_1' value='in_post_1' />
<input type="submit" value="Submit" name="B1"></p>
</form>
<p>&nbsp;</td>
</tr>
<tr>
<td >Often we need to check the existence of a variable before
initialization; we may use isset function</td>
</tr>
</table>
</body>
</html>
 

Code: Server Side

<?php
$fname = $_POST['fname'];
// Evaluates as true because $fname is set
if (isset($fname))
{
// first check it is not empty
if(empty($fname))
{
echo "Sorry No Blanks please";
die("<br/> Try again");
}
else
{
echo( " <br/>Thank you $fname");
}

// then authorize
if($fname=="Peter")
{
echo '<br/>Thank you again '. $fname. ' <br/>';
}
else
{
echo "<br/>Thank you $fname you are not authozied to view";
die("<br/>Good Bye");
}
}

?>
<html>
<head><title> Beautiful page</title>
</head>
<body>
I am visible to people with an authorized name. <?php echo " like you <h3>".$fname."</h3>"; ?>
</body>
</html>

Step: Run Time View

with a blank input

with a Name that would not match

With an authorized Name

Note the HTML page is loaded