How can PHP developers avoid dependencies on register_globals=on when accessing server variables like HTTP_REFERER?
When register_globals=on is enabled, server variables like HTTP_REFERER are automatically turned into global variables, which can lead to security vulnerabilities and unpredictable behavior. To avoid dependencies on register_globals=on, PHP developers should explicitly access server variables using superglobals like $_SERVER['HTTP_REFERER'] instead.
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
Related Questions
- What potential pitfalls should be considered when using the file() function in PHP?
- What are some potential pitfalls of comparing passwords in PHP using unsafely stored values in a database?
- How can error handling be implemented in PHP to display a default image if the specified image file is not found?