squiblo Posted February 6, 2010 Share Posted February 6, 2010 How can I get the hash stored in a variable? www.domain.com/#1234 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/191173-url-hash-value-into-a-variable/ Share on other sites More sharing options...
salathe Posted February 6, 2010 Share Posted February 6, 2010 You can use parse_url like: $hash = parse_url('www.domain.com/#1234', PHP_URL_FRAGMENT); echo $hash; Quote Link to comment https://forums.phpfreaks.com/topic/191173-url-hash-value-into-a-variable/#findComment-1007992 Share on other sites More sharing options...
wildteen88 Posted February 6, 2010 Share Posted February 6, 2010 Do you mean you want to get this #1234 from the url? It is not possible to retrieve this value in PHP as it is not sent in the request to the server. You can however get it via javascript. Quote Link to comment https://forums.phpfreaks.com/topic/191173-url-hash-value-into-a-variable/#findComment-1007993 Share on other sites More sharing options...
squiblo Posted February 6, 2010 Author Share Posted February 6, 2010 yes, that is what i meant if i set the hash to something like... #?hash=1234 could i do this... $hash = $_GET['hash']; if that is not possible, how can a javascript variable be placed in a php variable Quote Link to comment https://forums.phpfreaks.com/topic/191173-url-hash-value-into-a-variable/#findComment-1007995 Share on other sites More sharing options...
wildteen88 Posted February 6, 2010 Share Posted February 6, 2010 yes, that is what i meant if i set the hash to something like... #?hash=1234 could i do this... $hash = $_GET['hash']; if that is not possible, how can a javascript variable be placed in a php variable If you url is site.come/file.php?hash=1234 then yes you can use $_GET['hash'] but not if the url is site.com/file.php#1234 Anything after the hash is not sent in the http request to the server. Why are you wanting to get the value after the hash in PHP? Quote Link to comment https://forums.phpfreaks.com/topic/191173-url-hash-value-into-a-variable/#findComment-1007996 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.