chroot函数使用_PHP chroot()函数与示例

﹏ヽ暗。殇╰゛Y 2023-03-05 11:58 68阅读 0赞

chroot函数使用

PHP chroot()函数 (PHP chroot() function)

The full form of chroot is “Change Root”, the function chroot()” is used to change the root directory, and, also changes the current working directory to “/“.

chroot的完整格式为“ Change Root”函数chroot()“用于更改根目录,并且还将当前工作目录更改为” /“

Syntax:

句法:

  1. chroot(directory);

Parameter(s):

参数:

  • directory – It defines the new root directory.

    directory –它定义了新的根目录。

Return value:

返回值:

It returns a Boolean value, “TRUE” – if root directory changes successfully or “FALSE” – if root directory does not change.

如果根目录成功更改,则返回布尔值“ TRUE”;如果根目录未更改,则返回“ FALSE”。

Note:

注意:

chroot() will not work on Windows PHP installations. As per the reference manual, the function is only available on PHP when using in CLI/CGI/Embedded SAPI.

chroot()在Windows PHP安装中不起作用。 根据参考手册,仅在CLI / CGI / Embedded SAPI中使用时,该功能仅在PHP上可用。

The chroot() function requires root privileges. Please refer to the official php.net manual before attempting this function PHP chroot() function

chroot()函数需要root特权。 尝试使用此函数之前,请参考php.net官方手册PHP chroot()函数

We are not responsible in any way of any damage this function may cause.

对于此功能可能造成的任何损害,我们概不负责。

The following is a sample output of the program,

以下是程序的示例输出,

  1. When Success:
  2. /
  3. root directory is changed...
  4. /home/folder1
  5. When fail:
  6. /
  7. root directory is not changed...

Example: PHP code to change the root director

示例:更改root导演PHP代码

  1. <?php
  2. echo getcwd();
  3. //making a directory
  4. mkdir("/home/folder1");
  5. // Change root directory
  6. $ret_value = chroot("/home/folder1");
  7. if($ret_value == true)
  8. echo "root directory is changed...";
  9. else
  10. echo "root directory is not changed...";
  11. // Get current directory
  12. echo getcwd();
  13. ?>

Output

输出量

  1. root directory is changed...
  2. /home/folder1

Reference: PHP chroot() function

参考: PHP chroot()函数

翻译自: https://www.includehelp.com/php/chroot-function-with-example.aspx

chroot函数使用

发表评论

表情:
评论列表 (有 0 条评论,68人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Chroot隔离文件

    文章目录 (1)原理 (2)命令介绍 (3)示例 (1)原理 首先要知道,人们使用容器的最初目的,并不是为了部署软件,而是

    相关 理解 chroot

    通过编写 chroot 来认识 chroot 发挥的作用和它带来的好处 chroot 在 Linux 系统中发挥了根目录的切换工作,同时带来了系统的安全性等好处。本文通过编写

    相关 bind的chroot使用

    bind是linux的DNS服务器程序.bind\-chroot是bind的一个功能,使bind可以在一个 chroot 的模式下运行.也就是说,bind运行时的/(根)目