What is the best way to create a warning page for external links in PHP?
When creating a warning page for external links in PHP, you want to ensure that users are aware they are leaving your site and potentially entering a different domain. One way to do this is by creating a custom warning page that displays a message informing users about the external link and giving them the option to proceed or go back.
<?php
// Check if the link is external
if (strpos($_GET['url'], 'yourdomain.com') === false) {
// Display a warning message
echo "<h1>Warning: You are leaving our site</h1>";
echo "<p>You are about to be redirected to an external website. Are you sure you want to proceed?</p>";
echo "<a href='{$_GET['url']}'>Yes, proceed</a> | <a href='javascript:history.back()'>No, go back</a>";
} else {
// If the link is internal, redirect the user
header("Location: {$_GET['url']}");
exit();
}
?>
Keywords
Related Questions
- How can the issue of headers already being sent be resolved in the context of PHP form processing?
- What are the limitations of running a PHP application on a CD, such as the inability to write to the CD during runtime?
- How can PHP code be optimized to handle sessions without relying on cookies for better cross-browser compatibility?