Welcome Guest, Not a member yet? Register   Sign In
how to read URL hash?
#1

[eluser]keevitaja[/eluser]
is there a way to access following:

http://site.com/#/var1/var2

i would need to get everything after # like segment_array() gives me
#2

[eluser]Bhashkar Yadav[/eluser]
you can you parse_url() function of PHP like
Code:
$u = parse_url($url);
$fragments = $u['fragment'];
#3

[eluser]keevitaja[/eluser]
how do i get the url into $url variable from browser?
#4

[eluser]Bhashkar Yadav[/eluser]
Code:
$_SERVER['REQUEST_URI']
#5

[eluser]keevitaja[/eluser]
it doesn't work that way. with site.com/test/#/var1 i get only test. everything after # is excluded
#6

[eluser]Bhashkar Yadav[/eluser]
ahhh, yes, you are right .. i am also digging into it to find the solution. sorry for giving wrong suggestion.

please share if you find solution.
#7

[eluser]@robertotra[/eluser]
Actually the url 'http//yoursite.ext/#/var1/var2' is equivalent to 'http//yoursite.ext/index.php#/var1/var2', because it refers to an anchor inside the index page.

The problem is that the whole fragment part (the one after the sharp sign '#') is not even sent by http headers to the server, because it is meant to be used by the client browser to locate the internal anchor inside the document: that's why you cannot use the parse_url associative array to manage it (you should already have the full url to do so).

The problem would seem apparently without solution unless you recognize that the anchor part can be retrieved by use of javascript inside the client browser: so you have to use AJAX to retrieve it and then push related content to the client.

Cheers
Roberto

#8

[eluser]Bhashkar Yadav[/eluser]
@roberto, you are right. i think one can get with location.hash in JS.
#9

[eluser]canado[/eluser]
yes everything after the # is clientside
you need to do a js detection for that
I did that for seo with flash, so I m redirecting in js to the same url without the #
#10

[eluser]Bhashkar Yadav[/eluser]
Canado, that's great ....




Theme © iAndrew 2016 - Forum software by © MyBB