Session application in PHP Development _ PHP Tutorial

Source: Internet
Author: User
Session application details in PHP development. Session refers to the time that a user spends browsing a website from entering the website to closing the browser. From the above definition Session, it refers to the time that the user spends browsing a website from entering the website to closing the browser. From the above definition, we can see that Session is actually a specific concept of time.

Generally, variables (server-side variables, the same below) on a page on a website cannot be used on the next page. with session, it is easy. The variables registered in the session can be used as global variables. In this way, the session can be used for user identity authentication, Program Status record, and parameter transfer between pages.

In php (as the mainstream development language) 3, how does one implement session?

Php (as the mainstream development language) 3 itself does not implement the session function. we only need to implement it in other ways, the most famous among them is php (as the mainstream development language) lib. Php (as the mainstream development language) lib has the most basic functions including user authentication, Session management, permissions, and database abstraction. The following describes how to use php (as the mainstream development language) lib to implement session.

1. first install php (as the mainstream development language) lib (Environment: win2000 + php (as the mainstream development language) 3.0.16 + apache (the most popular WEB server platform on the Unix platform) 1.3.12 + php (as the mainstream development language) lib7.2c + MySQL (the best combination with PHP) 3.23.21 for win32)

First, we will unbind php (as the mainstream development language) lib, which contains a "php (as the mainstream development language)" directory, copy this directory to the installation directory of apache (the most popular WEB server platform on the Unix platform. For example, apache (the most popular WEB server platform on Unix) is installed in the d: apache (the most popular WEB server platform on Unix) directory, copy the "php (as the mainstream development language)" directory to d: apache (the most popular WEB server platform on the Unix platform ), and copy the files and directories under the pages directory (excluding the directory itself) of php (as the mainstream development language) lib directory to d: apache (the most popular WEB server platform on Unix) under htdocs.

The class library of php (as the mainstream development language) lib needs to be initialized according to the system, and local may need to be modified. inc file, which contains some basic parameters and can be modified based on the actual situation of your machine.

D: apache (the most popular WEB server platform on Unix) php (as the mainstream development language) prepend. A section of the php (as the mainstream development language) file is changed to the following:

If (! Isset ($ _ php (as the mainstream development language) LIB) or! Is_array ($ _ php (as the mainstream development language) LIB )){
$ _ Php (as the mainstream development language) LIB ["libdir"] = "d:/apache (the most popular WEB server platform on Unix) /php (as the current mainstream development language)/"; // put the path of php (as the current mainstream development language) under lib (as the current mainstream development language) Directory
}

Modify d: apache (the most popular WEB server platform on Unix) php (as the mainstream development language) local. inc file:

Class DB_Example extends DB_ SQL {
Var $ Host = "localhost"; // Host name of the MySQL database (the best combination with PHP)
Var $ Database = "test"; // Database name
Var $ User = "root"; // database username
Var $ Password = "1234567"; // database user Password
}

Finally, the initial table is generated based on the create_database.MySQL (the best combination of php and PHP) file in the stuff subdirectory under the lib directory of php (as the mainstream development language.

Every page that uses php (as the mainstream development language) lib must first find the library file necessary to run php (as the mainstream development language) lib, we can use php (as the mainstream development language ). the auto_prepend variable is set in ini to support. php (as the mainstream development language) lib contains a prepend. php (as the mainstream development language) file, and specify auto_prepend as "d:/apache (the most popular WEB server platform on Unix) /php (as the mainstream development language)/prepend. php (as the mainstream development language) "(with quotation marks), each page will automatically contain the php (as the mainstream development language) lib class library, we can also add the Directory of the lib class library in php (as the mainstream development language) to the include variable to locate these files. 2. call the page_open () function.

On every page that uses php (as the mainstream development language) lib, you must first call the page_open function for initialization. for example:

Bytes. From the above definition...

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.