Hi,
I have the following code in my index.php
Main purpose: I have a logout routine which works fine, but I wish to kill the session when any user closes the browser window without logging-out.
I believe this can be achieved using cookies in conjunction with sessions.
I wish to incorporate cookies into this page so that the session is killed as soon as the user closes the browser window.
Requesting forum members to help help me with the code.
I tried some combinations but failed!
<?
$db_name = "mydb";
$db_user = "mydbuser";
$db_pass = "mydbuserpass";
session_start();
if($_POST['submit'] == 'Submit')
{
$db=mysql_connect ("localhost", $db_user, $db_pass) or die ('Cannot connect to MySQL: ' . mysql_error());
mysql_select_db ($db_name) or die ("Sorry, database Problems.Please try again.");
$username = $_POST['username'];
$query = "select client_name, client_email from login where username = '".$username."' and password= '".$_POST['password']."'";
$result = mysql_query($query);
$value = mysql_fetch_array($result);
$num_rows = mysql_num_rows($result);
if($num_rows > 0) {
$_SESSION["client_name"] = $value['client_name'];
$_SESSION["client_email"] = $value['client_email'];
header("location:list.php");
}
else
{
echo "<div align='center'><font color='#FF0000' face='Verdana' size='1'>Invalid Username or Password!!</font></div>";
}
}
?>
<html>
<head>
<title>Login </title>
</head>
<body onLoad="document.forms[0].elements[0].focus()">
<div align="center">
<center>
<br>
<b><font face="Verdana" color="#FF0000" size="4">Login:</font></b>
<form name="login" action="<?php $_SERVER["PHP_SELF"] ?>" method="post">
<table border="1" cellpadding="4" cellspacing="4" style="border-collapse: collapse" bordercolor="#F0F0F0" width="293">
<tr>
<td width="290" colspan="2" bgcolor="#F0F0F0"><b>
<font size="2" face="Verdana">Login</font></b></td>
</tr>
<tr>
<td width="88"><b><font size="2" face="Verdana">Username</font></b></td>
<td width="202"><font face="Verdana">
<input type="text" name="username" size="20"></font></td>
</tr>
<tr>
<td width="88"><b><font size="2" face="Verdana">Password</font></b></td>
<td width="202"><font face="Verdana">
<input type="password" name="password" size="20"></font></td>
</tr>
<tr>
<td width="293" colspan="2" align="center"><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="B2"></td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>