Skip to content
PHP Logo

What potential pitfalls should be considered when embedding PHP in HTML files?

One potential pitfall when embedding PHP in HTML files is the risk of exposing sensitive information, such as database credentials or API keys, if the file is accessed directly by users. To mitigate this risk, it is important to store sensitive information in a separate configuration file outside of the web root directory and include it in your PHP files using include or require statements.

php
// config.php
<?php
$database_username = 'your_username';
$database_password = 'your_password';
$api_key = 'your_api_key';
?>

// index.php
<?php
require_once('config.php');
// rest of your PHP code here
?>