PHP Tutorial - PHP chroot() Function






Definition

The chroot() function changes the root directory of the current process to directory, and changes the current working directory to "/".

Syntax

PHP chroot() Function has the following syntax.

chroot(directory);

Parameter

ParameterIs RequiredDescription
directoryRequired.Path to change the root directory to

Return

PHP chroot() Function returns TRUE on success. FALSE on failure.

Note

This function requires root privileges, and is only available to GNU and BSD systems.





Example

Change the root directory:


<?php
// Change root directory
chroot("/path/to/chroot/");

// Get current directory
echo getcwd();
?>

Example 2

The following code shows how to change the root directory.



<?php
   // Change root directory
    chroot("c:/");

   // Get current directory
    echo getcwd();
?>