This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Dreamweaver > February 2006 > Secured area how to ?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Secured area how to ?
Pyna

2006-02-28, 6:21 pm

Hi,
I'm having a secured area where the username and pasw are stored in a mysql Db.

How can i get a message or store details of users access (who, when, which
page,...) to the protected area ?
Any help is more than welcome !
thx



this is the code i use in the connect.php

********************************************************************************
*************************************
<?php
define ('DB_USER', '*************'); // Database User Name
define ('DB_PASSWORD', '***********'); // Database User Password
define ('DB_HOST', '**********'); // Host Name (mostly localhost)
$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD); // Establishes
connection
mysql_select_db(**************'); // database name to connect to

define(TABLE_NAME,'user'); // Table Name
define(USER_NAME,'username'); // Username Field Name
define(PASS_NAME,'password'); // Password Field Name
?>

********************************************************************************
**************************************************

This is the code i use in the index.php page

********************************************************************************
**************************************************
<?php
session_start();

//site_defines
$SECURED_PAGE = 'index2.php';

// If the form was submited check if the username and password match
if($_POST == 1){
//Call the database file
require_once("connect.php");
$username = $_POST;
$password = $_POST;
$user_query = @mysql_query("SELECT * FROM " . TABLE_NAME . " WHERE `" .
USER_NAME . "`='$username' AND `" . PASS_NAME . "`='$password'");

if(@mysql_num_rows($user_query) > 0){
//Make sessions
$_SESSION = 'yes';
$_SESSION = $_POST;

// Redirect to the page
header("Location: $SECURED_PAGE");
exit();
} else {
$message = 'Uw username en/of password is niet correct !';
}
}
?>
<?php

//Check if we are displaying a message to the user:
if($message != NULL){?>
<table width="500" border="0" cellpadding="3" cellspacing="0"
bgcolor="#CCCCCC" align="center">
<tr>
<td><div align="center"><strong><font
color="#FF0000"><?=$message;?></font></strong></div></td>
</tr>
</table>
<?php } ?>
<form action="<? echo $_SERVER;?>" method="post" name="adminlogin"
id="adminlogin" style="display:inline;">
<br><br><br><br><table width="500" border="1" align="center" cellpadding="5"
cellspacing="0" bordercolor="#336699">
<tr bgcolor="#99CCFF">
<td colspan="2"><div align="center"><strong>Please
Login</strong></div></td>
</tr>
<tr>
<td width="47%"><strong>Username:</strong></td>
<td width="53%"><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td><strong>Password:</strong></td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td colspan="2"><div align="center"><font face="Georgia, Times New
Roman, Times, serif"><strong>
<input name="Submit" type="submit" id="Submit" value="Inloggen">
<input name="submitid" type="hidden" id="submitid" value="1">
</strong></font> </div></td>
</tr>
</table>
<p>&nbsp;</p>
</form>


bregent

2006-02-28, 6:21 pm

Create an audit table to save the details. When a restricted page is accessed, insert a row with the appropriate data.
Pyna

2006-02-28, 6:21 pm

thx for your advice, but i'm complete new in PHP and found this script on the
web and it works fine...after a lot of trouble...yes new to php...

so could you give me an example or something more explanation ?


Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews