使用 php 返回到上一页


Pass back to exact previous page using php

我的网站上有一个活动日历,我想将用户传递回上一页。目前我正在使用几个 php 函数来做到这一点,但它没有有效地传递回上一页,即因为以前的 url 使用 & ,它被阻止了新的超链接。这是我正在使用的:

$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; // Get The URL
<a href='"event.php?id=$event_id&url=$url'"> // Pass Url To Next Page
if(isset($_GET['url'])) {
    $backlink = $_GET['url'];
    $user_backlink = "<a href='"$backlink'"><div id='"posts'" class='"sidebarSectionLink sideback'">Back To Results</div></a>";
} else {
    $user_backlink = "<a href='"events.php'"><div id='"posts'" class='"sidebarSectionLink sideback'">Start A Search</div></a>";
}
echo $user_backlink // Link Back to previous

问题是这只是回显http://www.website.co.uk/events.php?type=def(之后没有其他内容) - 如何让它传递完整的 url 字符串?

使用 javascript 而不是 PHP 可以省去很多麻烦:

<a href="window.history.go(-1);">previous page</a>

你需要使用 urlencode:

http://php.net/manual/fr/function.urlencode.php

所以

<a href='"event.php?id=$event_id&url=$url'">

需要:

<a href='"event.php?id=$event_id&url=".urlencode($url)."'">

然后结束,

$backlink = $_GET['url'];

需要:

$backlink = urldecode($_GET['url']);
这个

怎么样:: JavaScript+PHP

echo "<script language=javascript> javascript:history.back();</script>";

它将与浏览器中的上一个按钮相同