Are there any common vulnerabilities in PHP websites that allow hackers to access specific files?

One common vulnerability in PHP websites is the ability for hackers to access specific files by exploiting directory traversal vulnerabilities. This occurs when user input is not properly sanitized, allowing attackers to navigate through directories and access sensitive files on the server. To prevent this, always sanitize and validate user input and use PHP functions like realpath() to ensure that file paths are secure.

$user_input = $_GET['file'];
$base_path = '/var/www/html/';

$file_path = realpath($base_path . $user_input);

if(strpos($file_path, $base_path) !== 0){
    die('Invalid file path');
}

// Proceed with file operations