PHP session details

Source: Internet
Author: User
Summary Session refers to the time that a user spends browsing a website from the website to the closed browser. From the above definition, we can see that the Session is actually a special Summary

Session refers to the time that a user spends browsing a website from the website to the closed 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 PHP3, how does one implement session?

Php3 itself does not implement the session function. we only need to implement it using other methods. The most famous one is phplib. The basic functions of phplib include user authentication, Session management, permission and database abstraction. The following describes how to use phplib to implement a session.

1. install phplib first (the environment is win2000 php3.0.16 Apache1.3.12 phplib7.2c mysql3.23.21 for win32)

First, unbind phplib. there is a 'php' directory in it. copy the directory to the Apache installation directory. For example, if Apache is installed in the d: \ Apache Directory, copy the 'php' directory to d: \ Apache and the pages directory of the phplib Directory (excluding the directory itself) copy the file and directory to d: \ Apache \ htdocs.

The phplib class library needs to be initialized according to the system. The local. inc file may need to be modified, which contains some basic parameters and can be modified based on the actual situation of your machine.

Change a program in the d: \ Apache \ php \ prepend. php file as follows:
If (! Isset ($ _ PHPLIB) or! Is_array ($ _ PHPLIB )){
$ _ PHPLIB ['libdir'] = 'd:/Apache/php/'; // path of the php directory under phplib
}

Corrected the d: \ Apache \ php \ local. inc file:
Class DB_Example extends DB_ SQL {
Var $ Host = 'localhost'; // Host name of the mysql database
Var $ Database = 'test'; // Database name
Var $ User = 'root'; // database username
Var $ Password = '000000'; // database user Password
}


Finally, the initial table is generated based on the create_database.mysql file in the stuff subdirectory under the phplib directory.

Because the page of each application phplib must first find the class library file necessary to run phplib, we can go to php. the auto_prepend variable is set in ini to support. phplib contains a prepend. php file, and specify auto_prepend as 'd:/Apache/php/prepend. php '(with quotation marks), the pages will take the initiative to include the phplib class library, we can also add the directory where the phplib class library is located to the include variable so that you can find these files.

2. call the page_open () function.

On each phplib page, you must first call the page_open function for initialization. for example:

<? Php
Page_open (array ('sess' => 'test _ Session '));
?>
The array variable (sess) is used to initialize some State-preserving objects. Note that phplib built-in names (sess) must be applied, which are defined in local. inc ..

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.