Home Backend Development PHP Tutorial Full session tutorial (2)_PHP tutorial

Full session tutorial (2)_PHP tutorial

Jul 13, 2016 pm 05:11 PM
session two exist accomplish I Tutorial yes of

2. Implementation of session in PHP3 and 4

There is no such thing as session in php3, but we need it, what should we do? Don't worry, there are many people who have done this for you, the most famous of which is phplib. You can download it abroad, and you can download it from most domestic PHP sites. The first thing we need to do is get phplib and php3 together to make it work. In order to achieve this function, we need to install phplib first. Follow me, it's very easy (the following method is passed on win2000+php3.0.16+apache1.3.12+phplib7.2c+MySQL3.23.21 for win32) The most basic functions of PHPlib include user authentication, session management, permissions and database Abstraction.

How to use PHPlib to implement the session function?

1. First, unzip phplib. There is a directory called "php" inside. Copy this directory to the apache installation directory. Take the author's machine as an example: My apache is installed in the d:/apache directory. I copied the "php" directory above to d:a/pache, and copied the files and directories in the pages directory under phplib to Under d:/apache/htdocs, be careful not to include the directory itself. The phplib class library needs to be initialized according to the system. You can modify the local.inc file, which contains some basic parameters. You can modify it according to the actual situation of your machine. Change a program in the d:/apache/php/prepend.PHP3 file to look like this:

if (!isset($_PHPLIB) or !is_array($_PHPLIB)) {
$_PHPLIB["libdir"] = "d:/apache/php/"; //Change this to the path of the PHP directory under phplib
}

Then change the d:/apache/PHP/local.inc file as follows:

class DB_Example extends DB_Sql {
var $Host = "localhost";//The host name of your MySQL database
var $Database = "test"; //Database name
var $User = "root";//Database user name
var $Password = "";//Database user password
}

The last step is to execute the create_database.MySQL file in the stuff directory in the unpacked phplib directory to generate the initial table. Let’s explain how phplib works. Every page that uses phplib must first find the class library files necessary to run phplib. We can set the auto_prepend variable in php3.ini to support it. The phplib distribution package contains a prepend.php3 file. After specifying "d:/apache/php/prepend.php3" (with quotes) for auto_prepend, 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 can be found. File, of course, the easiest way is to specify the absolute path of PHPlib. This is not a good idea, the portability is too poor!

Second step, in every page using phplib, you must first call the page_open function for initialization. This tells PHPlib that you will need to save state now or in the future. A typical
An example of page_open is as follows:

page_open(array("sess" => "Example_session"));
?>

Array variables (sess) are used to initialize some state saving objects. Note: phplib built-in names (sess) must be used. These built-in names are defined by you in local.ini. The page_open function must output the page content to the browser. was called before. The PHP3 script should end with page_close(), which will write the relevant status data back to the database. If you forget, you should be able to think of the result, haha, all your variables are lost, don’t blame me for not telling you. ...

Because phplib uses Cookies to save state information, the page_open() function must be called before the page content is output to the browser. The page content here can be any HTML information or blank lines. If you find the error "Oops - SetCookie called after header has been sent", this indicates what was output to the browser before page_open(). You should pay special attention to blank lines, because they are very difficult to find. Typical errors are in the tags Blank lines are output between. You should check whether the local.inc and prepend.PHP3 files contain blank lines. This is also a very error-prone place. In order to reduce the possibility of errors, we can write the initialization program like this:
page_open(array("sess" => "Example_session"));
?>

.....

The third step is specific use.
When a user visits the website, the user's session starts immediately. If the user's browser supports cookies, a session ID will be created and placed in the cookie. This unique ID is randomly generated by PHP3, and then used The random seed string has been md5 encrypted. The cookie here should be called a session cookie, because this cookie will not be written to the user's hard drive. When a session ends, the cookie will also be completed. If the user's browser does not support cookies, then the session ID will be put into the URL chain. Because it is encrypted, it is useless to steal it. The session ID stores user-related information, such as the user has been authenticated, authentication expiration time, user permissions, and other information you may need for our convenience. Session is actually the process of a user session. Session is not just used to track user registration. In fact, it can also be used in other situations. You can use it to store any information you want to store. This information can be sent to the pages that the user subsequently visits. Useful, of course, the premise is that those pages use PHPLIB. The method is very simple. After registering a variable, you can use it in subsequent pages until the session ends. Method:
register( "variable_name"); ?>

Note that the variable_name here is not the variable value, but the variable name. You can specify the variable name first and then assign the value. You can change the value of a variable in a page, and subsequent pages will get the changed value when accessing the variable. The types of variables are diverse and can be a string, a number, or an array. To illustrate with an example:

First page:
page_open(array("sess" => "Example_session"));
$sess->register( "first"); //Note that there is no need to add $ before the variable name
if (iset($firstname)) {
$first = $firstname;
}
.....
page_close();
?>

Second page:
page_open();//Start session


echo $first;//See the effect

page_close();//Save status information
?>

After registering a variable, when the page finally calls the page_close() function, each session variable will be written back to the database. If you forget to call the page_close() function, the variables will not be written back to the database, and unpredictable consequences will occur. When the variable is used and you no longer need it, you can call the following function to delete the variable:

page_open(array("sess" => "Example_session"));
...
$sess->unregister( "variable_name");
...
page_close();
?>

PHPLIB 7.0 uses a storage structure that allows you to store session data in a database, shared memory or LDAP. PHPLIB uses database classes, which gives you more choices. You can choose Oracle8, MySQL, postgresql and other databases to save status information.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629568.htmlTechArticle2. Implementation of session in PHP3 and 4. There is no such thing as session in php3, but we What should I do if I need it? Don’t worry, there are many people who have done this for you, the most famous of which is...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1262
29
C# Tutorial
1234
24
Tutorial on how to use Dewu Tutorial on how to use Dewu Mar 21, 2024 pm 01:40 PM

Dewu APP is currently a very popular brand shopping software, but most users do not know how to use the functions in Dewu APP. The most detailed usage tutorial guide is compiled below. Next is the Dewuduo that the editor brings to users. A summary of function usage tutorials. Interested users can come and take a look! Tutorial on how to use Dewu [2024-03-20] How to use Dewu installment purchase [2024-03-20] How to obtain Dewu coupons [2024-03-20] How to find Dewu manual customer service [2024-03-20] How to check the pickup code of Dewu [2024-03-20] Where to find Dewu purchase [2024-03-20] How to open Dewu VIP [2024-03-20] How to apply for return or exchange of Dewu

How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

PHP Programming Guide: Methods to Implement Fibonacci Sequence PHP Programming Guide: Methods to Implement Fibonacci Sequence Mar 20, 2024 pm 04:54 PM

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

What software is photoshopcs5? -photoshopcs5 usage tutorial What software is photoshopcs5? -photoshopcs5 usage tutorial Mar 19, 2024 am 09:04 AM

PhotoshopCS is the abbreviation of Photoshop Creative Suite. It is a software produced by Adobe and is widely used in graphic design and image processing. As a novice learning PS, let me explain to you today what software photoshopcs5 is and how to use photoshopcs5. 1. What software is photoshop cs5? Adobe Photoshop CS5 Extended is ideal for professionals in film, video and multimedia fields, graphic and web designers who use 3D and animation, and professionals in engineering and scientific fields. Render a 3D image and merge it into a 2D composite image. Edit videos easily

Tutorial on how to turn off the payment sound on WeChat Tutorial on how to turn off the payment sound on WeChat Mar 26, 2024 am 08:30 AM

1. First open WeChat. 2. Click [+] in the upper right corner. 3. Click the QR code to collect payment. 4. Click the three small dots in the upper right corner. 5. Click to close the voice reminder for payment arrival.

How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

Master how Golang enables game development possibilities Master how Golang enables game development possibilities Mar 16, 2024 pm 12:57 PM

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

See all articles