PHP chroot() function: Here, we will find out about the PHP chroot() function with its syntax, parameters, returns a type, and example.
PHP chroot() function
The full type of chroot is “Change Root“, the function chroot()” is utilized to change the root registry, and, likewise changes the present working index to “/”.
- registry – It characterizes the new root index.
It restores a Boolean value, “Genuine” – if root registry changes effectively or “False” – if root index doesn’t change.
chroot() won’t chip away at Windows PHP establishments. According to the instructional pamphlet, the function is just accessible on PHP when utilizing in CLI/CGI/Embedded SAPI.
The chroot() function requires root benefits. If it’s not too much trouble allude to the authority php.net manual before endeavouring this function PHP chroot() function
We are not dependable at all of any harm this function may cause.
Coming up next is an example output of the program,
When Success: / root directory is changed... /home/folder1 When fail: / root directory is not changed...
Example: PHP code to change the root chief
<?php echo getcwd(); //making a directory mkdir("/home/folder1"); // Change root directory $ret_value = chroot("/home/folder1"); if($ret_value == true) echo "root directory is changed..."; else echo "root directory is not changed..."; // Get current directory echo getcwd(); ?>
root directory is changed... /home/folder1