I have created a login system with some validation which all works fine, however I want to be able to create a session when the user logs in and then store this session information in a table that I have allready created.
The table has the following values
id
ip_address
session_id
user_id (the user id is stored in a table called 'user'
the login page which processes the users login and redirects the user to the members page is..
<?php
include'database_conn.php';//connect to the database
if(isset($_COOKIE['ID_my_site']))//checks if there is a login cookie
{
$username = $_COOKIE['ID_my_site'];//if there is a cookie it logs you in and directs you to the page
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE email = '$email'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
else
{
header("Location:../site/members.php");
}
}
}
if (isset($_POST['submit'])) {//runs if form has been submitted
if(!$_POST['email'] | !$_POST['pass']) {//makes sure the user has filled the form in
die('You did not fill in a required field.');
}
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);//checks the form against the database
}
$check = mysql_query("SELECT * FROM users WHERE email = '".$_POST['email']."'")or die(mysql_error());//gives error is user doesnt exsist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database. <a href=../site/register.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
if ($_POST['pass'] != $info['password']) {//gives error if the password is wrong
die('Incorrect password, please try again.');
}
else {
$_POST['email'] = stripslashes($_POST['email']);//if login is ok we add a cookie
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['email'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
header("Location:../login/process.members.php");//else redirect them to area
}
}
}
?>
Any help with adding the session to the mySQL table would be greatly appreciated