...

View Full Version : How to add security and sessions



bhagyaa2ze
02-22-2007, 07:52 AM
Hi,

Iam new to PHP,how to add sesssions and secruity to the following code for the admin page.


<?php
function login()
{ global $err;
include("head.php");
?>
<tr><td> <table border="0" cellpadding="0" cellspacing="0" height="150" width="200" align="center">
<tr>
<td height="20" align="center" bgcolor="#ffffff">
<font color="#000000">Admin Login</font>
</td>
</tr>
<tr>
<td valign="top">
<form action="" method="post"><br>
<table border="0" cellpadding="3" cellspacing="0" align="center">
<tr>
<td width="64">
<b>Username:</b></td>
<td width="134"><input type="text" name="aname" value="<?php echo $name;?>" /></td>
</tr>
<tr>
<td>
<b>Password:</b></td>
<td>
<input type="password" name="apass" value="<?php echo $pass;?>"></td>
</tr>
<tr>
<td colspan="2">
<center><input type="hidden" name="maa" value="do_login"><input type="submit" name="submit" value="Submit"></center>
<input type="hidden" name="Refer" value="<? echo($refer) ?>"
</td>
</tr>
</table>
</form>

</td></tr>
</table> </td></tr>
<tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td><?php echo $err; ?></td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr>
<?php footer(); }

function do_login()
{

global $err;
$name="admin";
$pass="admin";
$adn=$_REQUEST['aname'];
$adp=$_REQUEST['apass'];
if(($name==$adn)&&($pass==$adp))
{
admin();
}
else
{
$err="<font color=\"#CC0033\"><div align=\"center\" class=\"style9\"><b>LOGIN_ERROR</b></div></font>";
login();
}

}


where i need to add sessions in the above code

dohdoh
02-22-2007, 07:59 AM
you can add set a session object in a session like this:
session_start();
$_SESSION['admin'] = true;

verify and protect the page ith this code:
session_start();
if($_SESSION['admin'] !== true) {
die('access denied');
}

aedrin
02-22-2007, 03:34 PM
1 topic per question please.

This is the third one?

Nightfire
02-22-2007, 03:37 PM
I know, seems like he's wanting to fool us and have each thread add a little extra code onto his script to finish it off for him



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum