Home Backend Development PHP Tutorial Conversation on the couch (4)_PHP tutorial

Conversation on the couch (4)_PHP tutorial

Jul 13, 2016 pm 05:19 PM
superior Method dialogue of site

There are many ways to change the skin of cats...

Of course, if your site is still running PHP3, you won’t be able to use any of the code so far. But don't despair - there is another solution available to PHP3 users. It's called PHPLIB, and it provides a set of useful classes that allow you to add session management to your PHP3. You can install it by following the instructions in the package. You will also need to modify the "local.inc" configuration file to create your own classes.
Like in PHP4, every time you initialize a session, you need to call the page_open() function in advance. PHPLIB returns a default class named Example_Session -- you can modify this value in the "local.inc" file -- which will be used in the following example:


$#@60;?php

page_open(array("sess" =$#@62; "Example_Session"));

?$#@62;

It is important to call page_open() before any output to the browser. In order to register your session variables, the following statement will do the job.
$#@60;?php

//Initialize a session page_open(array("sess" =$#@62; "Example_Session"));

//Register one session variable $sess-$#@62;register(username);

?$#@62;

Each page must also contain the corresponding page_close() function to confirm that all changes are saved in the database.

$#@60;?php

page_close();

?$#@62;

Apart from these, most of the code is the same. Take a look at the PHPLIB version of the previous example:

$#@60;?php


//Initialize a session page_open(array("sess" =$#@62; "Custom_Session"));

/ /Register session variables - note the syntax
$sess-$#@62;register(username);
$sess-$#@62;register(stock1);
$sess-$#@62; register(stock2);
$sess-$#@62;register(stock3);
$sess-$#@62;register(stock4);

//Connect to MySQL $db = mysql_connect("someserver.com", "tom", "jones");

//Select the database mysql_select_db("stock_db",$db);

//Use SQL to query the database
$query = "select stock_pref1,stock_pref2,stock_pref3,stock_pref4
from user_info where username=$username";

$result = mysql_query($query,$db);

// Get the stock code from the database and assign it to the session variable
list($stock1,$stock2,$stock3,$stock4) = mysql_fetch_row($result);

//Output
echo "Hi $usernam #@60;br$#@62;";
echo "Your selected stocks are:$#@60;br$#@62;";
echo "$stock1$#@ 60;br$#@62;";
echo "$stock2$#@60;br$#@62;";
echo "$stock3$#@60;br$#@62;";
echo "$stock4$#@60;br$#@62;";

//Generate the rest of the page code

//Save the data to the database

page_close();
?$#@62;

As you can see, once you put down the PHP4 version, it is not difficult to understand the PHPLIB version - it will not be surprising when you know that the internal support for sessions in PHP4 is largely based on the PHPLIB module. If you are interested, PHPLIB actually goes deeper into identity authentication and permission classes in session management. It allows you to give a user the power to allow or prohibit processing in database-based authentication management - you can take a look. Examples of how to use these features are included in the documentation.

PHPLIB also provides some interesting built-in functions.

unregister(variable)

This news has a total of 2 pages, currently on page 1 1 2

Allows you to unregister a variable from a particular session. Note that in that case, the variable is not deleted, but its value will be lost at the end of the page because it is no longer saved to the database.

$#@60;?php

page_open(array("sess" =$#@62; "Example_Session"));

//Register a variable $sess-$ #@62;register(username);

//Check if it has been registered
if($sess-$#@62;is_registered(username))
{
echo "Variable "username" is registered!$#@60;br$#@62;";
}
else
{
echo "Variable "username" is unregistered!$#@60; br$#@62;";
}

//Unregister a variable $sess-$#@62;unregister(username);

//Check whether it has been logged out if ($sess-$#@62;is_registered(username))
{
echo "Variable "username" is registered!$#@60;br$#@62;";
}
else
{
echo "Variable "username" is unregistered!$#@60;br$#@62;";
}

page_close();

?$#@62;

is_registered(variable) If a session has been registered, return true, otherwise return false.

$#@60;?php

page_open(array("sess" =$#@62; "Example_Session"));

if($sess-$#@62 ;is_registered(username))
{
echo "A session variable by the name "username" already
exists";
}
else
{
$sess-$ #@62;register(username);
}

page_close();

?$#@62;

delete() releases the current session.

An interesting point to note is that in the cookie mode of PHPLIB, it is possible to start a new session after calling delete(), set a new cookie on the client, or even re-register some previous cookies. Session variables - can make changing the session virtually on the fly. Of course, if you do things like this, you need to get your life going...fast!

url($url) allows you to redirect the user to a new page.

self_url() returns a reference to the URL of the current page, including PHP_SELF and QUERY_STRING information.

So finally, for those of you who are unfortunate enough to have an ISP that does not provide PHP4 and PHPLIB - remember, it is always possible to simulate a session with good cookie technology. All you have to do is set a cookie with information to retain the user's visit to your site for a long time, and process this information each time the user visits a new page. It's primitive -- but it works, and sometimes you can't kill a simple way of doing something!

The patient leaves the hospital

Patient: Wow, doctor -- that's great! Thank you so much for everything!

Psychiatrist: No problem, Victor. I'd be happy to help you. Feeling better now?

Patient: Oh, easy! When I first came in, the whole sky looked gray and gloomy -- now, the view outside this awning window has never been better...

Psychiatrist: Well... Victor ...if I were you I would be very careful out there, the handrails are a little broken and may not be safe there.

Patient: Don't worry, doctor -- on days like this, I feel divine...ahah! ! ! !

This news contains 2 pages, currently on page 2 1 2

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532659.htmlTechArticleThere are many ways to reskin cats... Of course, if your site is still running PHP3, you can Unable to use any of the code so far. But don't despair -- there's another one available for PHP3 users...
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)

How to set up the keyboard boot function on a GIGABYTE motherboard (enable keyboard boot mode on GIGABYTE motherboard) How to set up the keyboard boot function on a GIGABYTE motherboard (enable keyboard boot mode on GIGABYTE motherboard) Dec 31, 2023 pm 05:15 PM

How to set up keyboard startup on Gigabyte's motherboard. First, if it needs to support keyboard startup, it must be a PS2 keyboard! ! The setting steps are as follows: Step 1: Press Del or F2 to enter the BIOS after booting, and go to the Advanced (Advanced) mode of the BIOS. Ordinary motherboards enter the EZ (Easy) mode of the motherboard by default. You need to press F7 to switch to the Advanced mode. ROG series motherboards enter the BIOS by default. Advanced mode (we use Simplified Chinese to demonstrate) Step 2: Select to - [Advanced] - [Advanced Power Management (APM)] Step 3: Find the option [Wake up by PS2 keyboard] Step 4: This option The default is Disabled. After pulling down, you can see three different setting options, namely press [space bar] to turn on the computer, press group

How to add trusted sites in Google Chrome How to add trusted sites in Google Chrome Jul 19, 2024 pm 04:14 PM

How to add trusted sites in Google Chrome? Some users cannot browse the web normally because the page prompts that it is not secure when surfing the Internet. At this time, they can add the website as a trusted site, and we can access it normally and surf the Internet smoothly. The editor below will bring you the steps to add a trusted site in Google Chrome. The steps are simple and easy to operate, and even beginners can easily get started. Friends who need it can learn about it together. How to add a trusted site in Google Chrome: 1. Open Google Chrome and click the three dots in the upper right corner. Click [Settings]. Choose privacy settings and security. (As shown in the picture) 2. Click Website Settings at the bottom of the page. (As shown in the picture) 3. Click on the unsafe content at the bottom of the page. (As shown in the picture) 4. Click the Add button to the right of the Allow option. (As shown in the picture) 5. Lose

The first choice for CS players: recommended computer configuration The first choice for CS players: recommended computer configuration Jan 02, 2024 pm 04:26 PM

1. Processor When choosing a computer configuration, the processor is one of the most important components. For playing games like CS, the performance of the processor directly affects the smoothness and response speed of the game. It is recommended to choose Intel Core i5 or i7 series processors because they have powerful multi-core processing capabilities and high frequencies, and can easily cope with the high requirements of CS. 2. Graphics card Graphics card is one of the important factors in game performance. For shooting games such as CS, the performance of the graphics card directly affects the clarity and smoothness of the game screen. It is recommended to choose NVIDIA GeForce GTX series or AMD Radeon RX series graphics cards. They have excellent graphics processing capabilities and high frame rate output, and can provide a better gaming experience. 3. Memory power

Digital audio output interface on the motherboard-SPDIF OUT Digital audio output interface on the motherboard-SPDIF OUT Jan 14, 2024 pm 04:42 PM

SPDIFOUT connection line sequence on the motherboard. Recently, I encountered a problem regarding the wiring sequence of the wires. I checked online. Some information says that 1, 2, and 4 correspond to out, +5V, and ground; while other information says that 1, 2, and 4 correspond to out, ground, and +5V. The best way is to check your motherboard manual. If you can't find the manual, you can use a multimeter to measure it. Find the ground first, then you can determine the order of the rest of the wiring. How to connect motherboard VDG wiring When connecting the VDG wiring of the motherboard, you need to plug one end of the VGA cable into the VGA interface of the monitor and the other end into the VGA interface of the computer's graphics card. Please be careful not to plug it into the motherboard's VGA port. Once connected, you can

Glodon Software's computer configuration recommendations; Glodon Software's computer configuration requirements Glodon Software's computer configuration recommendations; Glodon Software's computer configuration requirements Jan 01, 2024 pm 12:52 PM

Glodon Software is a software company focusing on the field of building informatization. Its products are widely used in all aspects of architectural design, construction, and operation. Due to the complex functions and large data volume of Glodon software, it requires high computer configuration. This article will elaborate on the computer configuration recommendations of Glodon Software from many aspects to help readers choose a suitable computer configuration processor. Glodon Software requires a large amount of data calculation and processing when performing architectural design, simulation and other operations. Therefore, the requirements for the processor are higher. It is recommended to choose a multi-core, high-frequency processor, such as Intel i7 series or AMD Ryzen series. These processors have strong computing power and multi-thread processing capabilities, and can better meet the needs of Glodon software. Memory Memory is affecting computing

How to solve the problem that the laptop cannot be shut down How to solve the problem that the laptop cannot be shut down Feb 25, 2024 am 09:24 AM

What should I do if my laptop won’t turn off? With the continuous development of technology, laptops have become an indispensable part of people’s lives. However, sometimes we may encounter a frustrating problem that the laptop won't shut down. Faced with this problem, how should we solve it? This article will discuss the reasons why the computer cannot shut down and how to deal with it. First, let’s take a look at why the laptop won’t shut down. Sometimes, this problem may be caused due to some bugs in the system. For example, it might be because

What is the best graphics card driver version? (Which graphics card driver version is the best) What is the best graphics card driver version? (Which graphics card driver version is the best) Jan 10, 2024 pm 11:13 PM

Which version of the graphics card driver is best to use? 1. There is no absolute best version. It is most important to choose the version that suits your computer; 2. Because the applicability and stability of the graphics card driver version are related to the computer hardware environment and system configuration; 3. You can check the detailed information of the computer and graphics card on the official website, select the appropriate driver version based on the information, or refer to the reviews of other users. It is recommended to back up the system before installing the driver to avoid unexpected situations. Graphics card driver version 472.19 series is an excellent choice. Currently, the driver compatibility of version 472 is the best. Installing version 472 of the driver can also maximize the performance of the graphics card. The NVIDIA graphics card driver Win7 installation version, numbered 2, 472.19, is a product with remarkable quality.

Please recommend a cost-effective 1155-pin CPU Please recommend a cost-effective 1155-pin CPU Jan 14, 2024 pm 01:30 PM

Please recommend which 1155-pin CPU is the best. The current 1155-pin CPU with the highest performance is Intel Corei7-3770K. It has 4 cores and 8 threads, a base frequency of 3.5GHz, and supports TurboBoost2.0 technology, which can reach up to 3.9GHz. In addition, it is equipped with 8MB of level 3 cache and is an excellent processor with the LGA1155 pin, the most powerful CPU Intel Core i73770K. The LGA1155 interface is the interface type used by second and third generation Core processors. The best performing one is Intel Core i73770K. The parameters of this processor are as follows: 1. Applicable type: desktop; 2. CPU series: Core i7; 3. CPU

See all articles