To provide my SESSIONS page, I have the following pages.
My questions
- Am I overreacting to this?
- Should I put a token in login.php instead of loginForm.php?
- When a user logs in, I save his IP address in the database. Should I use this for authentication?
Thanks to the community.
Login form loginForm.php
$token = md5(uniqid(rand(),TRUE)); <input name="login" type="text" class="textfield" id="login" /> <input name="password" type="password" class="textfield" id="password" /> <input type="hidden" name="token" value="<?php echo $token; ?>" /> <input type="submit" name="Submit" value="Login" />
When the user registers login.php
$fingerprint = sha1('SECRET-SALT'.$_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].$_POST['token']); session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_TOKEN'] = $_POST['token']; $_SESSION['SESS_FINGERPRINT'] = $fingerprint; session_write_close(); header("location: index.php"); exit();
Authentication on every page auth.php
session_start(); $fingerprint = sha1('SECRET-SALT'.$_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].$_SESSION['SESS_TOKEN']); if( !isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '') || ($_SESSION['SESS_FINGERPRINT'] != $fingerprint) || !isset($_SESSION['SESS_TOKEN']) || (trim($_SESSION['SESS_TOKEN']) == '') ) { header("location: denied.php"); exit(); }
source share