Hi all,
I have encountered a problem in my log-in page when my user opens a new window in the area and go to other pages (this action kills the session resulting in not be able to view the members' area anymore)..It might be a bit difficult to understand what i said above, please visit the following page and do the steps below in order to get the full understanding of my problem..
load: http://www.absolutethree.com
enter test for username and testing for password.
Once inside the login area, click 'Explore' via right-click-> open new window
In this new window, go to the page ( http://www.absolutethree.com)
Go back to the old window and click (normal left click) 'Explore'
There will be errors showing division by zero, this is due to the fact that the sessions were destroyed and members' details can't be retrived from the database.
How can I prevent the session to be destroyed this way? I only want the session to be destroyed upon pressing the logout button...not when user open new window and go to my homepage (think the homepage destroys my sessions..)
My homepage code(for the front part of code):
<?php
session_start();
header("Cache-control: private"); //IE 6 Fix
ob_start();
echo'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
echo"<html><head>";
echo'<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">';
echo'<META NAME="description" CONTENT="Absolute III is an unique free online game. This game is played through your browser, no download needed.">';
echo'<META NAME="keywords" CONTENT="Absolutethree, AbsoluteIII, browser, game, online, MMORPG, Singapore">';
echo"<title>Absolute III-An unique browser based game in Singapore</title>";
echo'<link rel="stylesheet" type="text/css" href="abs.css">';
?>
<SCRIPT type="text/JavaScript">
Image1= new Image(92,35)
Image1.src="images/button_signupon.gif";
Image2= new Image(92,35)
Image2.src="images/button_forumon.gif";
Image3= new Image(92,35)
Image3.src="images/button_guideon.gif";
Image4= new Image(92,35)
Image4.src="images/button_rankson.gif";
Image5= new Image(92,35)
Image5.src="images/button_creditson.gif";
var currenttime = '<?php print date("F d, Y Hi", time())?>'
window.status ="Server time: "+ currenttime+ "hrs"
</SCRIPT>
<?php
echo"</head><body>";
include("connect.php");
$a=1;
$link=@mysql_pconnect($mysqlhost,$mysqluser,$mysqlpasswd);
if($link==FALSE){
echo "<p><b>Unfortuantely, no link to the database can be made. Therefore, no results. Try later.</body></html>\n";
exit();}
mysql_select_db($mysqldbname,$link);
if(isset($_POST[Submit])) { //If submit is pressed, process it
$result=mysql_query("SELECT * FROM users WHERE username = '$_POST[mainuser]' AND password = '$_POST[mainpswd]'",$link ) or die(mysql_error());
$num_rows=mysql_num_rows($result);
if ($num_rows==0) {
$a=0;
} else {
// register and start sessions
$_SESSION['name'] = $_POST['mainuser'];
$_SESSION['pswd'] = $_POST['mainpswd'];
$current =$_SESSION['name']; //save username to current array
$result=mysql_query("SELECT * FROM users WHERE username = '$current'",$link ) or die(mysql_error());
$newarray=mysql_fetch_array($result);
if ($newarray[Status]=='D') header("Location: popex.php");
else {
$insert_login=mysql_query("INSERT INTO users_activity (kname,ip_add,login) VALUES('$newarray[kname]','$_SERVER[REMOTE_ADDR]',NOW())",$link ) or die(mysql_error());
//get this id inserted and store in session['id']
$_SESSION['id']=mysql_insert_id();
header("Location: loginmain.php");
}
}
mysql_close();
}
Any help will be greatly appreciated. Thank you.