动态插入文本和链接到另一个网页

Inserting text and link dynamically into another webpage

本文关键字:另一个 网页 链接 插入文本 动态      更新时间:2023-09-26

我有一个网页,将有一堆外部链接。当用户单击其中一个时,他们将被带到免责声明页面,通知他们将离开该站点。他们可以选择回去或者继续。我想要一个免责声明页面,这是与外发URL和特定链接的文本被点击上一页填充。是否可以在单独的网页中插入这些元素?

试试下面的代码。base64_encode允许使用GET方法安全地传递url。然后你必须检查这个键是否存在于你的目标页面中,如果用户说他们不想离开网站,然后重定向回,如果用户想离开网站,重定向向前。

<?php     
    // Place this on your page
    $currentPage = base64_encode(curPageURL());
    $outgoingPage = base64_encode("someurl.com");
    // creates a link that passes on the page that it came from and the page to go to if the user chooses to do so  
    echo "<a href='disclaimer.php?return={$currentPage}&go={$outgoingPage}'>Leave Page</a>";
?>
<?php
    // when the button is clicked to cancel leaving the page
    if(isset($_GET["return"])) {
     header("Location: ".base64_decode($_GET["return"]));  
    } else {
     header("Location: someDefaultPage.php");  
    }
    // and if the button to leave the page is clicked
    if(isset($_GET["go"])) {
     header("Location: ".base64_decode($_GET["go"]));  
    } else {
     header("Location: someDefaultPage.php");  
    }
?>