Home Backend Development PHP Tutorial DZ Forum core code analysis-core file global.func.php_PHP tutorial

DZ Forum core code analysis-core file global.func.php_PHP tutorial

Jul 21, 2016 pm 02:57 PM
code analyze document core plan forum

Please read the previous article: DZ Forum Core Code Analysis Plan - Install Package

It took two days to analyze global.func.php. I also planned to complete the common.inc.php file in three days, but found that many files were separated. So this time the post will change the strategy. Let’s first analyze the global.func.php file. . Poor analysis. I don't understand what a lot of things are for. . . We even found several functions that were not referenced in the entire DZ file system. Maybe it's a test function. But it's very useful. I took it and put it in my own function package.
Because this package has a lot of code. Carefully analyze each code block only for the personally important ones.
In the last article analysis plan, I actually missed two files. One is the DZ Forum global variable declaration table. DZ forum file role table. DZ Forum function call table.
Because there are relatively few things to analyze at the moment, I haven’t uploaded them here. Let’s wait until everything is done.
The study diary is as follows:

Only part of it is updated. . . . There is another part. . Will update in the afternoon

The following is the quoted content:
Golbal.func.php
Diary time: October 7, 2008 10:37:34
1. This file is a frequently quoted file, so the beginning Still adopt the usual constant judgment method. Prevent it from being opened directly by malicious browsers
2. The encryption in the encryption function authcode has multiple md5 superimposed encryptions. Keep passwords secure. In common thinking, it is generally only encrypted once. And in DZ's encryption function. Encryption algorithms are complex. Encryption from md5, encryption with random character truncation, encryption with bit operations and encryption with key.
3. DZ’s character processing works very well. Although we will choose utf-8 or gbk when downloading. But whether you are dealing with characters or database links, character encoding is the first place to consider. The format is determined on the database link of the db_mysql.class.php file. The code is as follows
$func = empty($pconnect) ? 'mysql_connect' : 'mysql_pconnect';

//Create a link to the attribute link of the class. And set the encoding method when establishing the link.

if(!$this->link = @$func($dbhost, $dbuser, $dbpw, 1)) {

$halt && $this->halt(' Can not connect to MySQL server');

} else {

if($this->version() > '4.1') {

global $charset , $dbcharset;

$dbcharset = $dbcharset2 ? $dbcharset2 : $dbcharset;

$dbcharset = !$dbcharset && in_array(strtolower($charset), array('gbk', ' big5', 'utf-8')) ? str_replace('-', '', $charset) : $dbcharset;

$serverset = $dbcharset ? 'character_set_connection='.$dbcharset.', character_set_results ='.$dbcharset.', character_set_client=binary' : '';

$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',').'sql_mode=''') : '';

$serverset && mysql_query("SET $serverset", $this->link);

}
The string processing in the global.func.php file also takes into account the encoding format of the string.
There is a global variable $charset which is used to set the encoding format. Cutstr processes strings based on the value of this variable.
In addition, in the cutstr() function, special characters in the string will be processed before truncation.


$string = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string);


After processing the truncation, restore it.


$strcut = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $strcut);
This can explain why the truncated text in the DZ forum still conforms to the original text format.
4. Customize the replacement of html code format. But here it should be noted that DZ is very thoughtful.

if(is_array($string)) {

foreach($string as $key => $val) {

$string[$key] = dhtmlspecialchars( $val); //If it is a numeric value, traverse the array and then call its own function to process a single character.

}
How to determine if the incoming string is an array? kindness. My idea is to only encapsulate the replacement part of the character. But he encapsulated it very well here. Because I don't have to worry about what format of string I pass when calling this function.
5. Encapsulate the page jump in the dheader function
6. //Typical reduction of code repetitive input functions. Process the email string. Only emailconv (email address) is needed to return an encoded email address
function emailconv($email, $tolink = 1) {

$email = str_replace(array('@', '.'), array('@', '.'), $email);

return $tolink ? ''. $email.'': $email;
}
7. //Truncate the file name, enter the file name, and return the processed file name
function fileext($filename ) {

return trim(substr(strrchr($filename, '.'), 1, 10));
}
8. DZ is used to deal with the problem of direct input path access by the browser Judgment constant method. But what about robots? There are no constants for robots. But php has a custom constant: $_SERVER['HTTP_USER_AGENT']. These two are used to determine the name of the robot. It also contains names. So the robot’s judgment method is as follows:
//By analyzing the common.inc.php file that calls this function. This function is used to determine how to handle the robot.
function getrobot() {

if(!defined('IS_ROBOT')) {

//Define the search engine name

$kw_spiders = 'Bot|Crawl |Spider|slurp|sohu-search|lycos|robozilla';

//Define browser type name

$kw_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';

//Determine whether it is one of these browsers. If so, define the IS_ROBOT constant as false. Otherwise, determine whether the spider is the search engine defined above, and if so, define the IS_ROBOT constant to be true. If neither condition is met, define the IS_ROBOT constant as false.

if(preg_match("/($kw_browsers)/i", $_SERVER['HTTP_USER_AGENT'])) {

define('IS_ROBOT', FALSE);

} elseif(preg_match("/($kw_spiders)/i", $_SERVER['HTTP_USER_AGENT'])) {

define('IS_ROBOT', TRUE);

} else {

define('IS_ROBOT', FALSE);

}

}

//Return the value of the IS_ROBOT constant

return IS_ROBOT;
}
The call in the common.inc.php file is handled like this:
//With this constant, robots are not allowed to access this page at will.
define('IS_ROBOT', getrobot());
if(defined('NOROBOT') && IS_ROBOT) {

exit(header("HTTP/1.1 403 Forbidden"));
}
Looks like it’s still the constant method. It's just that the value of this constant is obtained through the function getrobot().

Update Errors: These are errors I learned from my analysis of where they were called. But it’s impossible for me to find out and change it, so I’ll explain it here
The following is the quoted content:
以下为引用的内容:
checklowerlimit():这个函数是用来检查积分限制的
checklowerlimit(): This function is used to check the points limit

以下为引用的内容:
dongxin1390008说:daddslashes函数是检查php.ini文件的'MAGIC_QUOTES_GPC选项是否打开,若这个关闭,很容易的可以进行sql注射,若关闭了,则使用addslashes对单引号,# 号进行转义 2008-10-6 17:33:30更新附件包将此注释加入
Thank you to the following people for their help

The following is the quoted content:
http://www.bkjia.com/PHPjc/364108.html
www.bkjia.comtrue
http: //www.bkjia.com/PHPjc/364108.htmlTechArticlePlease read the previous article: DZ Forum Core Code Analysis Plan--It took two days to install the package. Global.func.php analysis completed. I also planned to complete the common.inc.php file in three days, but found that it was separated again...
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. Mar 21, 2024 pm 09:17 PM

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box &quot;Error 0x80004005: Unspecified Error&quot; will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

How to transfer files from Quark Cloud Disk to Baidu Cloud Disk? How to transfer files from Quark Cloud Disk to Baidu Cloud Disk? Mar 14, 2024 pm 02:07 PM

Quark Netdisk and Baidu Netdisk are currently the most commonly used Netdisk software for storing files. If you want to save the files in Quark Netdisk to Baidu Netdisk, how do you do it? In this issue, the editor has compiled the tutorial steps for transferring files from Quark Network Disk computer to Baidu Network Disk. Let’s take a look at how to operate it. How to save Quark network disk files to Baidu network disk? To transfer files from Quark Network Disk to Baidu Network Disk, you first need to download the required files from Quark Network Disk, then select the target folder in the Baidu Network Disk client and open it. Then, drag and drop the files downloaded from Quark Cloud Disk into the folder opened by the Baidu Cloud Disk client, or use the upload function to add the files to Baidu Cloud Disk. Make sure to check whether the file was successfully transferred in Baidu Cloud Disk after the upload is completed. That's it

What is hiberfil.sys file? Can hiberfil.sys be deleted? What is hiberfil.sys file? Can hiberfil.sys be deleted? Mar 15, 2024 am 09:49 AM

Recently, many netizens have asked the editor, what is the file hiberfil.sys? Can hiberfil.sys take up a lot of C drive space and be deleted? The editor can tell you that the hiberfil.sys file can be deleted. Let’s take a look at the details below. hiberfil.sys is a hidden file in the Windows system and also a system hibernation file. It is usually stored in the root directory of the C drive, and its size is equivalent to the size of the system's installed memory. This file is used when the computer is hibernated and contains the memory data of the current system so that it can be quickly restored to the previous state during recovery. Since its size is equal to the memory capacity, it may take up a larger amount of hard drive space. hiber

Discuz Forum Permission Management: Read Permission Setting Guide Discuz Forum Permission Management: Read Permission Setting Guide Mar 10, 2024 pm 05:33 PM

Discuz forum permission management: Read the permission setting guide In Discuz forum management, permission setting is a crucial part. Among them, the setting of reading permissions is particularly important, as it determines the scope of content that different users can see in the forum. This article will introduce in detail the reading permission settings of the Discuz forum and how to flexibly configure it for different needs. 1. Basic concepts of reading permissions In the Discuz forum, reading permissions mainly include the following concepts that need to be understood: Default reading permissions: Default after new user registration

Detailed explanation of the role of .ibd files in MySQL and related precautions Detailed explanation of the role of .ibd files in MySQL and related precautions Mar 15, 2024 am 08:00 AM

Detailed explanation of the role of .ibd files in MySQL and related precautions MySQL is a popular relational database management system, and the data in the database is stored in different files. Among them, the .ibd file is a data file in the InnoDB storage engine, used to store data and indexes in tables. This article will provide a detailed analysis of the role of the .ibd file in MySQL and provide relevant code examples to help readers better understand. 1. The role of .ibd files: storing data: .ibd files are InnoDB storage

Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Jun 12, 2024 pm 08:38 PM

Since the launch of ChatGLM-6B on March 14, 2023, the GLM series models have received widespread attention and recognition. Especially after ChatGLM3-6B was open sourced, developers are full of expectations for the fourth-generation model launched by Zhipu AI. This expectation has finally been fully satisfied with the release of GLM-4-9B. The birth of GLM-4-9B In order to give small models (10B and below) more powerful capabilities, the GLM technical team launched this new fourth-generation GLM series open source model: GLM-4-9B after nearly half a year of exploration. This model greatly compresses the model size while ensuring accuracy, and has faster inference speed and higher efficiency. The GLM technical team’s exploration has not

Create and run Linux ".a" files Create and run Linux ".a" files Mar 20, 2024 pm 04:46 PM

Working with files in the Linux operating system requires the use of various commands and techniques that enable developers to efficiently create and execute files, code, programs, scripts, and other things. In the Linux environment, files with the extension &quot;.a&quot; have great importance as static libraries. These libraries play an important role in software development, allowing developers to efficiently manage and share common functionality across multiple programs. For effective software development in a Linux environment, it is crucial to understand how to create and run &quot;.a&quot; files. This article will introduce how to comprehensively install and configure the Linux &quot;.a&quot; file. Let's explore the definition, purpose, structure, and methods of creating and executing the Linux &quot;.a&quot; file. What is L

Analysis of the reasons why the secondary directory of DreamWeaver CMS cannot be opened Analysis of the reasons why the secondary directory of DreamWeaver CMS cannot be opened Mar 13, 2024 pm 06:24 PM

Title: Analysis of the reasons and solutions for why the secondary directory of DreamWeaver CMS cannot be opened. Dreamweaver CMS (DedeCMS) is a powerful open source content management system that is widely used in the construction of various websites. However, sometimes during the process of building a website, you may encounter a situation where the secondary directory cannot be opened, which brings trouble to the normal operation of the website. In this article, we will analyze the possible reasons why the secondary directory cannot be opened and provide specific code examples to solve this problem. 1. Possible cause analysis: Pseudo-static rule configuration problem: during use

See all articles