How to verify the login user name and password with Php+sqlite3

Source: Internet
Author: User
Tags php class sqlite database

Session: In a computer, especially in a network application, it is called "conversation control." The Session object stores the properties and configuration information required for a specific user session. This way, when a user jumps between the application's Web pages, the variables stored in the session object are not lost, but persist throughout the user's session. When a user requests a Web page from an application, if the user does not yet have a session, the Web server automatically creates a Session object. When the session expires or is discarded, the server terminates the session.

Instance PHP Create SQLite database

Create a MyDB class and inherit the SQLite3 class, and instantiate a DB object.

<?php class MyDB extends SQLite3 {function __construct () {$this->open (' test.db ');}} $db = new MyDB (); if (! $db) {echo $db->lasterrormsg ();} else {echo "opened database successfully\n";}?>

PHP CREATE TABLE

Executes the SQL statement through the Exec method of the DB.

<?php class MyDB extends SQLite3 {function __construct () {$this->open (' test.db ');}} $db = new MyDB (); if (! $db) {echo $db->lasterrormsg ();} else {echo "opened database successfully\n";} $sql =<<<eof CREATE tabl E Company (ID int PRIMARY KEY is not null, the NAME TEXT not NULL, the age INT is not NULL, ADDRESS CHAR (), SALARY REAL); EOF; $ret = $db->exec ($sql); if (! $ret) {echo $db->lasterrormsg ();} else {echo "Table created successfully\n";} $db->close ();?>

PHP Insert Data

As with the method of creating the table, the SQL statement is executed through the Exec method of the DB.

<?php class MyDB extends SQLite3 {function __construct () {$this->open (' test.db ');}} $db = new MyDB (); if (! $db) {echo $db->lasterrormsg ();} else {echo "opened database successfully\n";} $sql =<<<eof INSERT into Company (Id,name,age,address,salary) VALUES (1, ' Paul ', +, ' California ', 20000.00); INSERT into Company (id,name,age,address,salary) VALUES (2, ' Allen ', +, ' Texas ', 15000.00); INSERT into company VALUES (3, ' Teddy ', id,name,age,address,salary, ' Norway ', 20000.00); INSERT into Company (id,name,age,address,salary) VALUES (4, ' Mark ', +, ' Rich-mond ', 65000.00); EOF; $ret = $db->exec ($sql); if (! $ret) {echo $db->lasterrormsg ();} else {echo "Records created successfully\n";} $db->close ();?>

Actual combat

The structure of the whole login program is login page, user Center, connection database.

Since no registration is added, create a user using create.php

create.php

<?php class MyDB extends SQLite3 {function __construct () {$this->open (' sqlite3.db ');}} $db = new MyDB (); if (! $db) {echo $db->lasterrormsg ();} else {echo "opened database successfully\n";} $sql =<<<eof CREATE tabl E Company (userid INT PRIMARY KEY is not NULL, username text is not null, password text is not null); EOF; $ret = $db->exec ($sql); if (! $ret) {echo $db->lasterrormsg ();} else {echo "Table created successfully\n";} $sql 2 =<<<eof INSERT into Company (Userid,username,password) VALUES (1, ' Popy32 ', $ (MD5 ("Popy32"))); EOF; $ret = $db->exec ($sql 2); if (! $ret) {echo $db->lasterrormsg ();} else {echo "Insert data successfully\n";} $db->close ();?>

login.php (Login processing)

Responsible for generating login pages and verifying login information

<?php header ("content-type:text/html; Charset=utf-8 "); Class MyDB extends SQLite3 {function __construct () {$this->open (' sqlite3.db ');}} $db = new MyDB (); if (! $db) {die ("Database access error". $db->lasterrormsg ());}?>

How to verify the login user name and password with Php+sqlite3

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.