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

PHP development basic tutorial constants

Concept

Constant can be understood as: a long-lasting value. After the constant value is defined, it cannot be changed anywhere else in the script.


1. Composition of constants

The writing form of constants is define(constant name, constant)

Note:

  • Constant names can be lowercase, but usually uppercase

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

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

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

Let’s define and call a constant:

Example:

<?php
//定義一個常量
define('Name','PHP.com');
//正確的調用方式
echo '我們是'.Name;
echo '<br/>';
//錯誤的調用方式
echo '我們是Name';
?>

Next, let’s verify several statements about constants

Example :

<?php
//其實可以小寫,但是不好區(qū)分出來,所以習慣上大家都大寫
define('age',27);
echo age;
//常量可以在外面不加引號
define(A,'安徽省');
echo A;
//只能用于標量,用于其他會報錯,例如數(shù)組
define('HF',array(1,2,3));
echo HF;
?>

Note 1: The constant definition is not quoted and can be output normally, but PHP will remind us that the definition is not standardized. Here Ntice

can Eliminate it by modifying the PHP configuration file. If you are interested, you can search and try to solve it yourself.

Note 2: The seven data types mentioned earlier can also be divided into three major categories

Scalar data types: Boolean, Integer, floating point, string

Composite data type: array, object

Special data type: NUll, resource type, callback Function

Note 3: After a constant is defined, it is a global variable by default and can be used anywhere in the entire running script.


2. Some built-in constants

The system also prepares 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.


##__FILE__The path of the current file on the server__FUNCTIOIN__Current function namePHP_VERSIONCurrent PHP Version__TRAIT____DIR____NAMESPACE__


Example:

<?php
//輸出當前所在行
echo __LINE__;
echo "<br/>";
//輸出當前文件所在服務器的路徑
echo __FILE__;
echo "<br/>";
//輸出當前PHP運行的操作系統(tǒng)
echo PHP_OS;
?>

Note: For the other few, you can try to output them. There are a few that you haven’t learned yet. You can learn them in later chapters. Detailed introduction


3. Use the defined() function to create a security mechanism

Knowledge here, Just understanding for now. 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 parentheses of the function. If the constant is defined, it returns true, otherwise it returns false

Assumption:

We have a set of online e-mall software that requires payment. Checking whether 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 check 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:

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

  • #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 file version.php is not included, the code after users.php will be executed.

Let’s experiment:

1.version.php file

The code is as follows:

<?php
//此處是檢查是否是否授權的業(yè)務部份代碼xxxx
define('AUTH',true);
//略過模擬代碼xxx行
?>

2.ser.php

The code is as follows:

<?php
//嘗試將include 'version.php'這一行代碼注釋后再執(zhí)行看看,對比結果
include 'version.php';
if(!defined('AUTH')){
    echo '非法!非法!你嘗試跳過授權文件';
    exit;
}

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

Note:

Function: include('pass in 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

Inclde will be explained in detail later

Continuing Learning
||
<?php //定義一個常量 define('Name','PHP.com'); //正確的調用方式 echo '我們是'.Name; echo '<br/>'; //錯誤的調用方式 echo '我們是Name'; ?>
submitReset Code
##Constant name

Description

__LINE__

The current line

__CLASS__

Current class name

##__METHOD__

????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

The operating system PHP runs on


##Trait name, added in php5.4

The directory where the file is located

The name of the current namespace (case sensitive)

<source id="t9rss"><div id="t9rss"><tfoot id="t9rss"></tfoot></div></source>

<button id="t9rss"></button>