jakebur01 Posted March 14, 2011 Share Posted March 14, 2011 How can I get http_referer to retrieve the anchor in the url? It keeps url variables, but it does not get the anchor. Example: http://example.com/ex.php?id=10#tab=3 All http_referrer catches is http://example.com/ex.php?id=10 code: $refer = $_SERVER['HTTP_REFERER']; <script type="text/javascript"> <!-- window.location = "<?PHP echo"$refer";?>" //--> </script> Quote Link to comment https://forums.phpfreaks.com/topic/230564-no-anchor-_serverhttp_referer/ Share on other sites More sharing options...
kenrbnsn Posted March 14, 2011 Share Posted March 14, 2011 Anchor tags are not passed to the server. Only the browser sees them and can act on them. If you want PHP to see an anchor tag, you would have to capture it with Javascript and send the value to PHP via AJAX. See http://www.w3schools.com/jsref/prop_loc_hash.asp for how to capture the hash via Javascript. Ken Quote Link to comment https://forums.phpfreaks.com/topic/230564-no-anchor-_serverhttp_referer/#findComment-1187228 Share on other sites More sharing options...
jakebur01 Posted March 14, 2011 Author Share Posted March 14, 2011 cool. that will work great. I'll pass it through in a hidden form field then attach it to the end of the http_referer . Thanks Ken. Quote Link to comment https://forums.phpfreaks.com/topic/230564-no-anchor-_serverhttp_referer/#findComment-1187231 Share on other sites More sharing options...
jakebur01 Posted March 14, 2011 Author Share Posted March 14, 2011 Still searching on how to store a javascript value into a php variable. I haven't figured it out yet. <?PHP $hash="<script type=text/javascript> document.write(location.hash); </script>"; ?> <input type="hidden" name="hash" id="textfield" value="<?php echo"$hash";?>"/> Quote Link to comment https://forums.phpfreaks.com/topic/230564-no-anchor-_serverhttp_referer/#findComment-1187236 Share on other sites More sharing options...
kenrbnsn Posted March 14, 2011 Share Posted March 14, 2011 If you tell us what you want to do, we might be able to suggest how you can to it. You're going to have to use AJAX to do it, since PHP executes and exits before the Javascript is run by the browser. Ken Quote Link to comment https://forums.phpfreaks.com/topic/230564-no-anchor-_serverhttp_referer/#findComment-1187242 Share on other sites More sharing options...
jakebur01 Posted March 14, 2011 Author Share Posted March 14, 2011 I basically have a page for updating information with 4 or 5 different tabs to navigate between. When the info is saved, I submit/post to the same page and I have an if $_POST statement at the top of the page that catches it. I am then trying to redirect to the the same page and same anchor. Quote Link to comment https://forums.phpfreaks.com/topic/230564-no-anchor-_serverhttp_referer/#findComment-1187245 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.