PHP可以使用js href.split在哈希后从URL中获取值


can php get value from url after hash with js href.split?

我有一些网址,比如http://www.domainname.com/m1.php?#m2.php?more=apple&starting=1

如何使用PHP获取值$_GET['more']&$_GET['starting']

是否可以使用 js href.split 来获取值 hehind 哈希#

更新的问题:

添加一些代码如下: 我仍然得到$_GET['fragment'] = m2.php?more=apple,但失去了&starting=1,下一步该怎么做?

<script type="text/javascript">
var parts = location.href.split('#');
if(parts.length > 1)
{
    var params = parts[0].split('?');
    var mark = '?';
    if(params.length > 1)
    {
        mark = '&';
    }
    location.href = parts[0] + mark + 'fragment=' + parts[1];
}
</script>
<?php
if(isset($_GET['fragment']))
{
    echo $_GET['fragment'];
}
?>

在 php 中,您根本看不到请求的片段。

你只能用javascript看到它

我认为你应该能够使用PHP的内置函数parse_url http://php.net/manual/en/function.parse-url.php

如果查看返回值,则可以将查询参数作为哈希获取,并且#后面的值是fragment

您可以执行此操作以使用 php 中的哈希片段。

需要重新加载页面,但它可以工作。您可以在任何其他 js 标记之前设置此脚本标记,这样重新加载就不会延迟。

<script type="text/javascript">
if(location.hash.length > 0){
    var hash = location.hash.replace('#','');
    location.href = hash;
    //or
    //location.href = 'index.php?param1=1&hash'+hash;
    //or
    //location.href = '<?=$_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'].'&hash='?>'+hash;
}
</script>