PHP is a commonly used language for developing dynamic WEB pages. I have studied the use of PHP Session and share it with you here. I hope it will be useful to everyone. PHP Session refers to the time that elapses from entering the website to closing the browser when the user is browsing a website, that is, the time the user spends browsing the website.
From the above definition, we can see that Session is actually a specific time concept. Generally speaking, variables (referring to server-side variables, the same below) in a certain page on the website cannot be used in the next page. It is easier to handle with session. Variables registered in the session can be used as global variables. In this way, we can use session for user identity authentication, program status recording, and parameter transfer between pages.
php3 itself does not implement the session function, we can only use other methods to achieve it , the most famous of which is phplib. The most basic functions of phplib include user authentication, session management, permissions and database abstraction. Next we will describe how to use phplib to implement session. First install phplib (the environment is win2000+php3.0.16+Apache1.3.12+phplib7.2c+mysql3.23.21 for win32). First, unzip phplib. There is a "php" directory inside. Copy this directory to the Apache installation directory. . For example: Apache is installed in the d:Apache directory, then copy the "php" directory to d:Apache, and copy the files and directories in the pages directory of the phplib directory (excluding the directory itself) to d:Apachehtdocs.
The phplib class library needs to be initialized according to the system. You may need to modify the local.inc file, which contains some basic parameters and can be modified according to the actual situation of your machine.
Change the program in the d:Apachephpprepend.php file to the following:
<ol class="dp-xml"> <li class="alt"><span><span>if (!isset($_PHPLIB) or !is_array($_PHPLIB)) { </span></span></li> <li class=""><span>$_PHPLIB["libdir"] = "d:/Apache/php/"; //放phplib下php目录的路径 </span></li> <li class="alt"><span>} </span></li> </ol>
Modify the d:Apachephplocal.inc file:
<ol class="dp-xml"> <li class="alt"><span><span>class DB_Example extends DB_Sql { </span></span></li> <li class=""> <span>var $</span><span class="attribute"><font color="#ff0000">Host</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">"localhost"</font></span><span>; //mysql数据库所在主机名 </span> </li> <li class="alt"> <span>var $</span><span class="attribute"><font color="#ff0000">Database</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">"test"</font></span><span>; //数据库名 </span> </li> <li class=""> <span>var $</span><span class="attribute"><font color="#ff0000">User</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">"root"</font></span><span>; //数据库用户名 </span> </li> <li class="alt"> <span>var $</span><span class="attribute"><font color="#ff0000">Password</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">"1234567"</font></span><span>; //数据库用户密码 </span> </li> <li class=""><span>} </span></li> </ol>
Finally according to The create_database.mysql file in the stuff subdirectory of the phplib directory generates the initial table. Since every page that uses phplib must first be able to find the class library files necessary to run phplib, we can set the auto_prepend variable in php.ini to support it. phplib contains a prepend.php file and specifies auto_prepend as "d: /Apache/php/prepend.php" (with quotes), each page will automatically include the phplib class library. We can also add the directory where the phplib class library is located to the include variable so that these files can be found. The above are some basic methods used by PHP Session. Have you learned it?