can php get value from url after hash with js href.split?
I have some urls like http://www.domainname.com/m1.php?#m2.php?more=apple&starting=1
How to use PHP to get the value $_GET['more']
& $_GET['starting']
?
Is it possible use js href.split
to get the value hehind hash #
?
Updated question:
Add some code as below: I still get the $_GET['fragment'] = m2.php?more=apple
, but lose the &starting=1
, How do I do next?
<script type="text/javascript">
var parts = location.href.split('#');
if(parts.length > 1)
{
var params = parts[0].split('?');
开发者_StackOverflow var mark = '?';
if(params.length > 1)
{
mark = '&';
}
location.href = parts[0] + mark + 'fragment=' + parts[1];
}
</script>
<?php
if(isset($_GET['fragment']))
{
echo $_GET['fragment'];
}
?>
In php you simply can't see the fragment requested.
You can see it only with javascript
I think you should be able to use PHP's built in function parse_url
http://php.net/manual/en/function.parse-url.php
If you look at the return values, you can get the query params as a hash and the value after the #
is the fragment
You can do this to use the hash fragment in php.
Needs page reload but it works. You can set this script tag before any other js tag so the reload is not delayed.
<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>
精彩评论