What are the potential pitfalls of hardcoding links in PHP scripts?
Hardcoding links in PHP scripts can lead to maintenance issues if the links need to be updated or changed in the future. To avoid this, it's better to store the links in a separate configuration file or database table, allowing for easier updates without modifying the code directly.
// Config file with links
$config = [
'home' => 'http://example.com',
'about' => 'http://example.com/about',
'contact' => 'http://example.com/contact',
];
// Accessing links from the config file
echo '<a href="' . $config['home'] . '">Home</a>';
echo '<a href="' . $config['about'] . '">About</a>';
echo '<a href="' . $config['contact'] . '">Contact</a>';