1, User personal information module design
1. Overview of user's personal information module After the user logs in, he can see the personal information. Here, users can view personal user name, permission level, current date, last login time, login times and perform safe exit operation. 2. User personal information module technology In the personal information display module, with the user ID stored in the SESSION variable as the condition, the user information is queried from the user information table, and the user information is output in the page. The key code of userinfo.php is as follows:
<?php
header("Content-Type:text/html;charset=utf-8");
date_default_timezone_set('PRC'); // Set to Beijing time
session_start(); // Initialize SESSION variable
include_once("conn/conn.php"); // Include profile
// echo "user id =". $_session ['id '];
// Search user information
// Perform query operation
$sqlstrvi = "select * from tb_meeting_user where userId = $_SESSION[id]";
$testrst = mysql_query($sqlstrvi);
// Take a row from the result set as an associative array
$testrst = mysql_fetch_array($testrst,MYSQL_ASSOC);
print_r($testrst);
?>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="58" align="center">honorific:</td>
<td width="48" align="left"><?php echo $testrst['userName']?></td>
<td width="68">Your identity:</td>
<td width="78" align="left">
<?php
// Judge user authority
if($testrst['userRights'] == 0){ // Ordinary users
echo "<span style=\"color:#C9f \ "> normal user < / span >";
}else if($testrst['userRights'] == 1){ // administrators
echo "<span style=\"color:#F00 \ "> administrator < / span >";
}
?>
</td>
<td>
//The current date is:
<span class="dates">
<?php echo date("Y year m month d day");?>
</span>
</td>
<td width="78">Last login:</td>
<td width="138">
<?php
if($testrst['userLoginCount'] == 1){ // Determine whether the user is logging in for the first time
echo "------";
}else{
echo $_SESSION["lasttime"];
}
?>
</td>
<td width="40">Currently:</td>
<td width="100" align="left">
//No. & nbsp;<?php echo $testrst['userLoginCount'];?> Log in times
</td>
<!--<td width="51"><a href="logout.php">Sign out</a></td>-->
<td width="51">
<a href="logout.php" onclick="return logout();">
<img src="images/over3.png" width="49" height="19" border="0" onclick="logout()" alt="Safe exit" />
</a>
</td>
</tr>
</table>
<script>
// Safe exit
function logout(){
if(confirm("Are you sure you want to log out?")){
// If the user confirms exit, open the logout.php page
window.open('logout.php','_parent','',false);
}else{
retrurn false;
}
}
</script>
It is worth mentioning that the last login time output by this module is not obtained directly by querying the content of related fields in the database, but from the lastiame stored in the SESSION variable.
The key code of logout.php is as follows:
<?php
header("Content-Type:text/html;charset=utf-8");
date_default_timezone_set('PRC'); // Set to Beijing time
session_start(); // Enable SESSION support
session_destroy(); // Destroy SESSION
// Back to home
echo '<script>alert(\'User has exited safely!\');location=(\'index.php\');</script>';
?>