Take a look into my LOGIN script:
PHP Code:
<?php
if(isset($_POST['enter'])) {
include $_SERVER['DOCUMENT_ROOT'] . '/connect/db_conn.php';
$password = md5($_POST['password']);
$nick = $_POST['nick'];
$password = mysql_real_escape_string($password);
$nick = mysql_real_escape_string($nick);
$nick = strtolower($nick);
if($password == '') {
$error .= "<li>Enter your password!</li>";
}
if($nick == '') {
$error .= "<li>Enter your Nick!</li>";
}
if(preg_match('/\W/', $password)) {
$error .= "<li>!!! No symbols !!!</li>";
} else {
if(preg_match('/\W/', $nick)) {
$error .= "<li>!!! No symbols !!!</li>";}}
$check = mysql_query("SELECT * FROM `test_sessions` WHERE nick='$nick' AND pass='$password'") or die(mysql_error());
if(mysql_num_rows($check) == 0) {
$error .= "<li>Wrong password or Nick!</li>";
}
if(isset($error)) {
$eroras = '<center><font color="grey">Mistakes:<br/><br/><font color="blue">'.$error.'</font></center>';
} else {
$r = mysql_fetch_array( $check ) or die(mysql_error());
session_start();
$code = md5($nick.$password);
$sess_time=date('ymdHis');
$sess_browser=$_SERVER['HTTP_USER_AGENT'];
$_SESSION['code'] = $code;
$_SESSION['time'] = $sess_time;
$_SESSION['browser'] = $sess_browser;
header("Location: index.php");
}
if($_GET['act'] == 'logout') {
session_start(); // begin session
session_unset();
session_destroy(); // remove the entire session
}
}
?>
<?php echo "$eroras";?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="lt">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="lt"/>
</head>
<body>
<form method='post' action='login[test].php'>
<table align='center'><tr><td> User:</td>
<br />
<td><input type='text' name='nick' size='15'></td>
</tr><tr><td>Password:</td>
<br />
<td><input type='password' name='password' size='15'><input type='submit' name='enter' value=' Enter '></td></tr></table>
<br />
</form>
</body>
</html>
I want to change this part:
PHP Code:
session_start();
$code = md5($nick.$password);
$sess_time=date('ymdHis');
$sess_browser=$_SERVER['HTTP_USER_AGENT'];
$_SESSION['code'] = $code;
$_SESSION['time'] = $sess_time;
$_SESSION['browser'] = $sess_browser;
To Create more powerful session...
I wonder if I could use cookie like:
PHP Code:
<?php
$hash = md5($nick.$password.$sess_time);
setcookie("hash", "$hash");
?>
and use it as variable $_SESSION['hash']...
As you can see all of that are just a scratch... But Maybe I can make something from all of this?
TIP: For now, I am not looking into other pages such as regenerating session_id or checking hash for user authentication... Just trying to create powerful session. Only Then i could look forward.
Bookmarks