Login Page:
Code: Select all
<?php
//checks if the form has been sent
if($_POST["postok"]) {
//receives form data
$nome = $_POST["nome"];
$passwd = $_POST["passwd"];
//records in the session if the fields aren´t blank
if ( (!empty($nome)) && (!empty($passwd)) ) {
//starts the session
session_start();
//registers session variables
$_SESSION["sess_nome"] = $nome;
$_SESSION["sess_passwd"] = $passwd;
}//closes (empty)
else {
$erro++; //increments de error variable by one
$html_error .= "<br><font face='Verdana' size='1' color='#5C718B'>Fields can´t be blank.</font>";
}//closes else
}//closes IF($_post)
?>
<html>
<head>
<title>sessoes</title>
<link href="./css/main.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><font size="1" face="Verdana"><strong>user authentication using sessions</strong></font></td>
</tr>
</table>
<hr noshade>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#EBEDE4">
<td height="31"><div align="center"><font size="1" face="Verdana">· record session data ·</font></div></td>
<td height="31"><div align="center"><font size="1" face="Verdana">· <a href="verifica.php">check session</a> ·</font></div></td>
<td height="31"><div align="center"><font size="1" face="Verdana">· <a href="logout.php">logout</a> ·</font></div></td>
</tr>
</table>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><font size="1" face="Verdana">the data willl be recorded in the session.</font></td>
</tr>
</table>
<br>
<?
//checks if form has been posted
if($_POST["postok"]) {
//checks if error has occured
if($erro) {
echo "<div align='center'>$html_error</div>";
}//closes if (error)
// if there´s no error ...
else {
echo "<br><br><table border='0' cellpading='0' cellspacing='0' width='90%'>";
echo "<tr>";
echo "<td><div align='center'><font face='Verdana' size='1'><b>session started !!</b></font></div></td>";
echo "</tr>";
echo "</table>";
}//closes ELSE(error)
} //closes IF(postok)
//displays the form
else { ?>
<form action="" method="post" name="frm_sessao">
<table width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="16%" height="25"><strong><font size="1" face="Verdana">Nome:</font></strong></td>
<td width="84%" height="25"><font size="1" face="Verdana">
<input name="nome" type="text" size="30" maxlength="30"></font></td>
</tr>
<tr>
<td height="25"><strong><font size="1" face="Verdana">Password:</font></strong></td>
<td height="25"><font size="1" face="Verdana">
<input name="passwd" type="password" size="8" maxlength="8"></font></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="btnEnviar" type="submit" value="record session data" class="input-butt"></div></td>
<input type="hidden" name="postok" value="1">
</tr>
</table>
</form>
<?
} //closes ELSE?>
</body>
</html>
?>Code: Select all
<?php
//starts the session
session_start();
session_register('sess_nome');
session_register('sess_passwd');
?>
<html>
<head>
<title>sessoes</title>
<link href="./css/main.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><font size="1" face="Verdana"><strong>user authentication using sessions</strong></font></td>
</tr>
</table>
<hr noshade>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#EBEDE4">
<td height="31"><div align="center"><font size="1" face="Verdana">· <a href="admin.php">record session data</a> ·</font></div></td>
<td height="31"><div align="center"><font size="1" face="Verdana">· check session ·</font></div></td>
<td height="31"><div align="center"><font size="1" face="Verdana">· <a href="logout.php">logout</a> ·</font></div></td>
</tr>
</table>
<br><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><font color="#FF0000" size="1" face="Verdana">results:</font></td>
</tr>
</table>
<br>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><font size="1" face="Verdana">
<?
//verifies if session variables are inicialized
if(!empty($_SESSION["sess_nome"]) && (!empty($_SESSION["sess_passwd"])) ) {
echo "<b>The session is active.</b><br><br>";
echo "Name ...........: ".$_SESSION["sess_nome"];
echo "<br>Passwd ............: ".$_SESSION["sess_passwd"];
}//Closes IF
//If nothing is registered , display message
else {
echo "<font color='#5C718B'>unregistered session.</font>";
} //closes else?></font></td>
</tr>
</table>
</body>
</html>
?>Code: Select all
<?php
<?
//starts the session
session_start();
//checks is the variables are registered
if( (!empty($_SESSION["sess_nome"])) AND (!empty($_SESSION["sess_passwd"])) ) {
//destroys the session
$destroi = session_destroy();
} //closes IF
?>
<html>
<head>
<title>sessoes</title>
<link href="./css/main.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><font size="1" face="verdana"><strong>user authentication using sessions !!! </strong></font></td>
</tr>
</table>
<hr noshade>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#EBEDE4">
<td height="31"><div align="center"><font size="1" face="Verdana">· <a href="admin.php">record session data</a> ·</font></div></td>
<td height="31"><div align="center"><font size="1" face="Verdana">· <a href="verifica.php">check session</a> ·</font></div></td>
<td height="31" bgcolor="#EBEDE4"><div align="center"><font size="1" face="Verdana">· logout ·</font></div></td>
</tr>
</table>
<br><br>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center"><font size="1" face="Verdana">
<?
//checks session destroy
if($destroi) {
echo "<b>user successfully logout !!</b>";
}
else {
echo "<b>An error has occured. Please try again.</b><br><br>";
echo "example: check if the session has been recorded.";
}
?></font></div></td>
</tr>
</table>
</body>
</html>
?>Any help would be apprecciated