johnnyjohnny Posted July 9, 2009 Share Posted July 9, 2009 is it possible to catch full php url, like this one? especially the part after #. http://foo.com/#additionalinfo thanks Quote Link to comment https://forums.phpfreaks.com/topic/165406-catch-php-url/ Share on other sites More sharing options...
p2grace Posted July 9, 2009 Share Posted July 9, 2009 yes echo $_SERVER['REQUEST_URI']; Quote Link to comment https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872343 Share on other sites More sharing options...
johnnyjohnny Posted July 9, 2009 Author Share Posted July 9, 2009 That's will only print "/" for me. yes echo $_SERVER['REQUEST_URI']; Quote Link to comment https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872344 Share on other sites More sharing options...
AviNahum Posted July 9, 2009 Share Posted July 9, 2009 very weird... but you can use JavaScript insted PHP... use this code to print the url: <script language="javascript" type="text/javascript"> document.write (document.location.href); </script> Quote Link to comment https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872347 Share on other sites More sharing options...
p2grace Posted July 9, 2009 Share Posted July 9, 2009 Any particular reason why it is #additionalinfo and not ?additionalinfo Quote Link to comment https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872350 Share on other sites More sharing options...
johnnyjohnny Posted July 9, 2009 Author Share Posted July 9, 2009 Not quite, the site I am working on is complete Ajax based, and the problem I ran into is the back/forth button and bookmark will not function, so to correct that the server side is going to catch the "#" part and decide what to display, so sadly it has to be processed on the server side. very weird... but you can use JavaScript insted PHP... use this code to print the url: <script language="javascript" type="text/javascript"> document.write (document.location.href); </script> Quote Link to comment https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872351 Share on other sites More sharing options...
p2grace Posted July 9, 2009 Share Posted July 9, 2009 I'd recommend either using a $_GET var then, or using htaccess and modrewrite to just take whatever is after the slash e.g. http://foo.com/additionalinfo a combo of modrewrite and $_SERVER['REQUEST_URI'] should accomplish the same goal and actually look cleaner. Quote Link to comment https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872353 Share on other sites More sharing options...
johnnyjohnny Posted July 9, 2009 Author Share Posted July 9, 2009 That's interesting, do you mind elaborate more on that more? I'd recommend either using a $_GET var then, or using htaccess and modrewrite to just take whatever is after the slash e.g. http://foo.com/additionalinfo a combo of modrewrite and $_SERVER['REQUEST_URI'] should accomplish the same goal and actually look cleaner. Quote Link to comment https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872371 Share on other sites More sharing options...
thebadbad Posted July 9, 2009 Share Posted July 9, 2009 AFAIK the fragment part of an URL can't be accessed by the server. It's for the client side (e.g. used in AJAX as you mention). But since you're using AJAX, it should be no problem to post the fragment to server side, right? Quote Link to comment https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872378 Share on other sites More sharing options...
p2grace Posted July 9, 2009 Share Posted July 9, 2009 Something like this should do the trick. Create a .htaccess file in the root directory of your website. Within it's contents put the following: RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?pg=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?pg=$1 This code above does the following: User accesses the page: http://foo.com/additionalinfo The rewrite converts this page to: http://foo.com/?pg=additionalinfo However the user doesn't see the conversion, it remains http://foo.com/additionalinfo to the user. But PHP can now parse the variable by $_GET['pg'] (even though it doesn't appear to exist). Quote Link to comment https://forums.phpfreaks.com/topic/165406-catch-php-url/#findComment-872380 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.