我使用此代码来发现网址的最后部分:
$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/