The phpajax user logs on and exits. This article focuses on the combination of ajax and php in jquery to achieve the effect of refreshing new logon. if you need it, please refer to it. In this example, we use the Mysql database to create a use. This article mainly introduces the combination of ajax and php in jquery to achieve the effect of refreshing new logon. if you need it, please refer to it.
In this example, we use the Mysql database to create a user table with the following table structure:
The code is as follows: |
|
Create table 'user '( 'Id' int (11) not null auto_increment, 'Username' varchar (30) not null comment 'username ', 'Password' varchar (32) not null comment 'password ', 'Login _ time' int (10) default null comment 'logon time ', 'Login _ IP' varchar (32) default null comment 'logon IP ', 'Login _ counts' int (10) not null default '0' comment' login times ', Primary key ('id ') ) ENGINE = MyISAM default charset = utf8; Insert a piece of user information data into the user table: Insert into 'user' ('id', 'username', 'password', 'login _ time', 'login _ IP', 'login _ counts ') VALUES (1, 'demo', 'fe01ce2a7fbac8fafaed7c982a04e229 ', '','', 0 ); |
After entering the user name and password, the user is prompted that the user has successfully logged on, and relevant logon information is displayed. if you click "exit", the user logon page is displayed.
Go to index. php. if the user is logged on, the logon information is displayed. if the user is not logged on, the logon box is displayed, asking the user to log on.
The code is as follows: |
|
User logon If (isset ($ _ SESSION ['user']) { ?> Congratulations! You are the first Login site. The last time I log on to this site is:
[Exit] User name: Password:
|
Note that in index. the PHP file header should be added with the statement session_start. at the same time, the jquery library and global. js, you can also write a beautiful CSS style for the login box, of course, this example has slightly written a simple style, please refer to the source code.