Phpajax user logon and exit _ PHP Tutorial

Source: Internet
Author: User
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.

The code is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.