About PHP Implementation of user login related knowledge points (a)

Source: Internet
Author: User
This article mainly introduces the PHP implementation of user login related knowledge points (a), has a certain reference value, now share to everyone, the need for friends can refer to

Content Summary:
-User Login process
-PHP Implementation Validation action
-PHP Implementation page Jump
-PHP's Operational database extension
-Advantages and disadvantages between different methods
-Advantages of PDO operation
-Session in PHP operation Method


# 1. Preparatory work

1. Writing a static login page
2. Build the operating environment
Configure a domain-based virtual host under Httpd-vhosts.conf,
adding domain names in the local DNS Hosts file
3. Create a database, create data tables, fields, test content
2. Login Flowchart

3. Perfect Case

    • Receive form data

    • Verifying data legitimacy

    • Verify Data rationality

    • Perform a successful jump


3.1 Receiving data


Get exposes data to URL parameters, and post is submitted to the server in a private way, so for some high-security-demanding data, use post

PHP receives a predefined variable for a form

    • The $_get is used to receive data that is submitted in a GET manner, including the form of a URL

    • $_post used to receive POST -Submitted data

    • $_request can receive both get and post submitted data


3.2 Verifying data legitimacy

This step determines whether the data is empty, using PHP's Empty () to determine


[PHP] Plain Text View Copy Code



?

1


BOOL Empty (mixed $var)


Determine if a variable is considered empty. When a variable does not exist, or its value is equal to FALSE, it is considered non-existent. If the variable does not exist,empty () does not produce a warning.

3.3 Verifying data rationality

Determine whether the user name password submitted by the form matches the user name password of the data, if matching, jump to the management homepage, as long as there is a mismatch, prompts the user error message, and jumps to the homepage

3.3.1 PHP Connection Database

First MySQL is a CS architecture software, so for PHP in the connection database at the client level, for PHP needs to connect to the database, you must open the corresponding operation database extension, find the corresponding code in php.ini, remove the previous semicolon restart Apche, for example

    • MySQL extension extension=php_mysql.dll

    • Mysqli extension Extension=php_mysqli.dll

    • PDO extension Extension=php_pdo_mysql.dll


Three characteristics:

Mysql:

1, the earliest operation database API, simple and easy to get started, provides a process-oriented interface

2, but from PHP 5.5.0 This extension has been deprecated and 7.0.0 from PHP. Started being removed

Mysqli:mysql Enhanced extended over version

1. Support for process-oriented and object-oriented

2, add preprocessing statements, exceptions, transaction capture, etc.

3, is only support MySQL database. This is definitely the best option if you don't operate other databases.

pdo:php Data Objects

1, supporting preprocessing statements, exception capture, transactions and other operations, only support object-oriented,

2, only need to encapsulate a class, you can freely switch databases to PostgreSQL, or SQL Server and other databases, and in the terminal does not make too much adjustment, its function is similar to JDBC, ODBC, DBI and other interfaces

3.3.2 using MySQL extension to connect to a database

    • Connect database mysql_connect ("Database Address", "User name", "password"); Returns a connection resource

    • set charset mysql_query (SQL instructions)

    • Execute SQL statement mysql_query ("select|update|delete| Insert statement ");
      Description: If the successful execution of Update|delete|insert returns TRUE, the failure returns false
      if the resource result set is successfully returned for select execution, the failure returns false

    • 5. Resource result set processing MYSQL_FETCH_ASSOC ($res);

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.