The following is my brief code for login area:
<?php
session_start();
echo"<html><head>";
echo"<title>Absolute III</title>";
echo'<link rel="stylesheet" type="text/css" href="game.css">';
?>
<script type="text/javascript">
var currenttime = '<?php print date("i", time())?>'
window.status =60-currenttime+ " minute(s) to next hourchange"
</SCRIPT>
<?php
echo"</head><body>";
include("connect.php");
$b=2;
if(($_SESSION['name']) && ($_SESSION['pswd'])) { //session registered
$b=1;
} else {
$b=0;
// must redirect to other unaccess section
header("Location: unaccess.php");
}
$current_time = (strtotime("now"));
$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);
$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);
//Update 'Lastlogin' column (for inactive detection)
list($year, $month, $day, $hour, $minute, $second) = explode(':', date('Y:n:d:H:i:s', time()));
$update_time = mktime($hour, $minute, $second, $month, $day, $year);
$update_login=mysql_query("UPDATE users SET Lastlogin='$update_time' WHERE username = '$current'",$link ) or die(mysql_error());
$result=mysql_query("SELECT * FROM users WHERE username = '$current'",$link ) or die(mysql_error());
$newarray=mysql_fetch_array($result);
list($year, $month, $day, $hour) = explode(':', date('Y:n:d:H', time()));
$now_time = mktime($hour, 0, 0, $month, $day, $year);
?>
//further codes below
// the following codes (not shown here) does not involve any sessions, it simply just display the details of newarray[]
The following is my homepage code which get the details and pass to the above scripts:
<?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();
}// further codes below
Further help will be greatly appreciated. Thank you