PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Yes, I start a new session when the user gets authenticated in another page and I want to access the sessionId in all other pages and compare it with the sessionId stored in db.
<?
if ($_POST["subAuthentication"] == "Sign In"){
$userValid = 0;
$error = "<center>";
$userName = $_POST["txtUserName"];
$query = "select Password from UserAccounts_tbl where UserName = '".htmlentities($_POST["txtUserName"])."' AND Password = '".$_POST["encryptedPass"]."' ";
$result = mysql_query($query);
if (mysql_num_rows($result) != 0) {
setcookie("userName", $userName, time() + (60*60*24*30));
if ($_POST["chStorePassword"]){
$pass = $_POST["txtPassword"];
//initiate new session and store sessionid in SessionDetails_tbl
session_start();
$sessionId = session_id();
$query = "insert into SessionDetails_tbl(SessionId, UserName, IpAddress) values('$sessionId', '$userName','{$_SERVER["REMOTE_ADDR"]}' )";
mysql_query($query);
$_SESSION["query"] = $query;
//set the cookie for password and user of local computer and also whether check box is checked
setcookie("computerUser", $userName, time() + (60*60*24*30));
setcookie("password", $pass, time() + (60*60*24*30));//will expire in 30 days
setcookie("checked", "true", time() + (60*60*24*30));
}
else{
setcookie("checked", "", time() + (60*60*24*30));//will expire in 30 days
setcookie("computerUser", "", time() + (60*60*24*30));
//setcookie("password", "", time() + (60*60*24*30));
}
?>
<script language="javascript">
window.location = "index.php";
</script>
<?
} else {
$error .= "Invalid username or password!!!";
}