国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP constants and variables use constants to restrict users from skipping certain files

長——Chinese literally means: long-lasting, unchanged for a long time.

Constant is easy to translate: a long-lasting value.

[Key knowledge] We define the knowledge level as: silent level

The scope of use of constants is very wide. We will use constants in the future to define our working directory, define some characteristics of account passwords, version numbers, etc. So this piece of knowledge is very important.

The definition and writing method of constants in the code:

define (constant name, constant value)

Note:

1. The constant value can only be the scalar we talked about in the previous chapter.

2. Constant names can be lowercase, but usually uppercase

3. Constant names can be without quotation marks, but usually with quotation marks.

4. When calling a constant in a string, it must be outside the quotation marks

5. It is recommended that only letters and underscores be used for constant names

Let’s experiment with code:

1. Try defining and calling a constant once

<?php

define('MY_NAME','PHP中文網(wǎng)');

echo MY_NAME;
//下面是錯誤的調(diào)用方式
echo '我的名字是MY_NAME';
//正確的調(diào)用方式該這么寫
echo '我的名字是' . MY_NAME;
?>

2. Pay attention to project experiments

<?php
//其實可以小寫,但是不好區(qū)分,所以我們規(guī)定通常大寫
define('xiaoxie',true);
echo xiaoxie;

//常量可以在外面不加引號
define(YH,'不要對未來迷茫,迷茫的時候靜下心來coding');
echo YH;

//只能用標(biāo)量,我在后面用了一個數(shù)組,大家學(xué)一下就行,會報錯的喲
define('BIAO',array(1,2,3));

?>

In addition, the system has also prepared some built-in constants for us. These constants are specified. Let’s get familiar with a few first. There are more system constants that we have studied in the previous volume. After getting started, we will slowly add and learn them.

The current lineThe path of the current file on the serverCurrent function nameCurrent class nameCurrent member method namePHP_OSThe operating system that PHP runs onPHP_VERSIONCurrent PHP versionTrait name ,php5.4 new additionThe directory where the file is locatedThe name of the current namespace (case sensitive)

defined() function is used as a security mechanism

You don’t need to master the knowledge here. After learning the function, you can look at this part of the code again.

defined() Let’s learn this usage, mainly to prevent others from bypassing the security check file.

Function: defined (constant)
Function: Pass the constant after the brackets of the function. If the constant is defined, it returns true, otherwise it returns false

[Scenario Simulation] Assume, we This set of online e-mall software requires payment. Checking whether the payment is made is done by checking the software authorization. The file version.php has the function of checking authorization. We have stipulated in the software that there is no authorization to check the file version. PHP cannot use this software. All code includes version.php. And in order to prevent someone from piracy, I can also encrypt the version.php code.

We have two files:

1. There is a version number, version statement and authorization statement in the middle of one file. The file name is version.php

2. A file has specific business functions. For example: user registration, login, etc., the file name is users.php

What should we do? ——That is to say, if the version.php file is not included, the code after users.php will be executed.

Let’s conduct an experiment:
version.php file

<?php

//此處是檢查是否是否授權(quán)的業(yè)務(wù)部份代碼xxxx
define('AUTH',true);

//略過模擬代碼xxx行

?>

users.php

<?php
//嘗試將include 'version.php'這一行代碼注釋后再執(zhí)行看看,對比結(jié)果
include 'version.php';

if(!defined('AUTH')){
   echo '非法!非法!你嘗試跳過授權(quán)文件';
   exit;
}


//模擬后面用戶注冊和用戶登陸的代碼xxx行
echo '用戶注冊';
?>

The experimental results show that version.php must be included, otherwise it will not be displayed The following echo 'User registration';


include
pronunciation: [?n?klud]
explanation: contains

version
pronunciation: [?v?:?n]
Explanation: Version

user
Pronunciation: [?juz?]
Explanation: Users
Plural: users

define
Pronunciation: [d??fa?n]
Explanation: Specifies

Function: include('Input file path and file name')
Function: The function of this function is to pass in the file with the specified path and let PHP include it for execution
Note: In the following chapters, we will specifically explain and experiment with include

Continuing Learning
||
<?php define('MY_NAME','PHP中文網(wǎng)'); echo MY_NAME; //下面是錯誤的調(diào)用方式 echo '我的名字是MY_NAME'; //正確的調(diào)用方式該這么寫 echo '我的名字是' . MY_NAME; ?>
submitReset Code
    <rt id="cvptw"><tr id="cvptw"></tr></rt>
      Constant nameDescription
      ##LINE
      FILE
      FUNCTIOIN
      CLASS
      METHOD
      TRAIT
      DIR
      NAMESPACE
        <li id="cvptw"><xmp id="cvptw">
        <span id="cvptw"></span>
          <bdo id="cvptw"></bdo>
            <span id="cvptw"></span>

            <bdo id="cvptw"></bdo>
            <rt id="cvptw"></rt>
            <li id="cvptw"></li>