How can hackers exploit insecure include() statements in PHP code?

Hackers can exploit insecure include() statements in PHP code by manipulating the file path parameter passed to the include() function, allowing them to execute arbitrary code on the server. To prevent this, it is important to validate and sanitize user input before using it in include() statements.

$filename = 'path/to/secure/file.php';

if (strpos($filename, '../') === false) {
    include($filename);
} else {
    die("Invalid file path");
}