获取不带参数的地址栏

发布于 2024-08-26 01:20:50 字数 263 浏览 2 评论 0原文

请帮助我获取不传递参数的浏览器地址栏的值。无需使用正则表达式和字符串函数。你能做到吗? (我在apache上使用php)。

进入

http://dev.mazda-parts.ru/catalogue/?spattern=1

退出

http://dev.mazda-parts.ru/catalogue/

Help me please get the value of the address bar of browser without the parameters passed. Without the use of regular expressions and string functions. You can do this? (I use php on apache).

enter

http://dev.mazda-parts.ru/catalogue/?spattern=1

exit

http://dev.mazda-parts.ru/catalogue/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌若浮生 2024-09-02 01:20:50

看看 $_SERVER 超全局。

<?php
//example
echo $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URL'];

Take a look at the $_SERVER superglobal.

<?php
//example
echo $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URL'];
回眸一遍 2024-09-02 01:20:50

parse_url() 可以帮助你,或者一些 php 字符串函数,比如 strtok()

parse_url() can help you, or some of the php string functions, like strtok()

ぇ气 2024-09-02 01:20:50

您说您想要最后一页的 URL,可以在 $_SERVER['HTTP_REFERER'] 变量中找到该 URL。

请注意,该值不可靠,因为客户端可以随意更改它。

如果您想要更准确地查找最后一页,可以使用会话。这是一个例子:

session_start();
$last_page = $_SESSION['pageurl'];
$_SESSION['pageurl'] = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URL'];

// $last_page now contains a more reliable value for the last url

You say that you want the URL of the last page, which can be found in the $_SERVER['HTTP_REFERER'] variable.

Beware that this value is not reliable as it can be freely changed by the client.

If you want a more accurate way of finding the last page, you can use sessions. Here's an example:

session_start();
$last_page = $_SESSION['pageurl'];
$_SESSION['pageurl'] = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URL'];

// $last_page now contains a more reliable value for the last url
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文