How can closedir() function be utilized to prevent security violations in PHP scripts?
When using opendir() in PHP scripts, it is important to always follow it with closedir() to prevent security violations such as leaving open directory handles. This can potentially lead to resource exhaustion and other security vulnerabilities.
$dir = opendir('/path/to/directory');
// Do something with the directory
closedir($dir);