javascript - 检测 URL 的最后一部分不起作用 - PHP

标签 javascript php jquery

我使用此代码来发现网址的最后部分:

$link = $_SERVER['PHP_SELF'];
$link_array = explode('/',$link);
$page = end($link_array);

自从我将项目从 000webhost 移至 Hostinger 后,它就无法正常工作

例如,www.google.com/hello.php/4441 应返回 4441,但它返回 hello.php

有人经历过吗?

最佳答案

documentation PHP_SELF$_SERVER 变量

The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/foo/bar.php would be /foo/bar.php. The FILE constant contains the full path and filename of the current (i.e. included) file.

因此,这将为您提供执行脚本的文件名,即 hello.php

您可能想要使用REQUEST_URI,它将返回整个 URI,而不是正在运行的脚本的文件名。

关于javascript - 检测 URL 的最后一部分不起作用 - PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53097744/

相关文章:

javascript - 虚拟数据库,导出多个默认值

PHP/MySQL : Unsure why variable does not contain a value

java - 如何让JSP调用Servlet更安全?

javascript - 如何使 jQuery 向上和向下箭头按钮逐步垂直滚动正文?

javascript - 如何为动态添加的元素初始化 JQuery 插件

javascript - 从另一个指令加载一个指令

javascript - jQuery validate plugin - 如何关闭非提交验证结果?

javascript - 递归调用 Promise 函数

php - 对表单元素集的多个 AJAX 请求

php - 函数中的类型声明会让我的代码执行得更好吗?