1
http://xxxx.us/a/6126/securitycheckzpsfc10cc9.jpg#id=558554

ハッシュ後に URL パラメータを取得したい。

$hash = $_GET['hash'];

動作しない

アドレスバーからURLを取得したい。ハッシュ後の部分を取得します。

<?php
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
$url1 = parse_url($url);
echo $url1['fragment'];
?>

これも機能しません。

4

2 に答える 2

1

javascript location.hashを使用して、ハッシュをGETパラメーターに変更し、それを PHP スクリプトに送信できます。

<!DOCTYPE HTML>
<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<a href="http://example.com/?some_parameter=x" class="hashed_link">Link</a>

<script>
    $().ready(function(){
        // navigate to in page anchor for testing
        window.location.href="#hash=12345678";

        // bind anchor click event
        $('.hashed_link').click(function(e){
            e.preventDefault();
            hash_anchor = $(this).attr('href')+'&'+location.hash.substr(1);

            alert(hash_anchor);
            //window.location.href=$(this).attr('href')+location.hash;
        });
    });
</script>
</body>
</html>
于 2013-06-21T19:27:24.113 に答える
0

ハッシュはサーバーに渡されず、クライアント側のみです。

あなたがしようとしていることは不可能ですが、Javascript を介して完全な URL を取得することは可能です。

自分がやりたいことを行うためのより良い方法を検討する必要があります。代わりに GET 値として渡してはどうでしょうか?

于 2013-06-21T19:16:17.227 に答える