dreamwest Posted August 27, 2009 Share Posted August 27, 2009 How can i get the current url without being referred from another page. I can get a referred url : $_SERVER['REMOTE_ADDR'] But if i just typed in the url in the address bar : http://site.com/url.php, how can i echo this url out Quote Link to comment https://forums.phpfreaks.com/topic/172107-get-url/ Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 $scheme = !empty($_SERVER['HTTPS']) && 'on' === $_SERVER['HTTPS'] ? 'https' : 'http'; echo $scheme, '://', $_SERVER['HTTP_HOST'], $_SERVER['SCRIPT_NAME']; Quote Link to comment https://forums.phpfreaks.com/topic/172107-get-url/#findComment-907415 Share on other sites More sharing options...
trq Posted August 27, 2009 Share Posted August 27, 2009 REMOTE_ADDR gets you a users ip address, not a url of any kind. Maybe you where thinking of HTTP_REFERER, but even then, it simply gets the refering address, not the current. Maybe you where thinking of REMOTE_HOST, again, this relates to the client. Maybe your looking for combination of SERVER_NAME, REQUEST_URI and QUERY_STRING? Quote Link to comment https://forums.phpfreaks.com/topic/172107-get-url/#findComment-907418 Share on other sites More sharing options...
dreamwest Posted August 27, 2009 Author Share Posted August 27, 2009 $scheme = !empty($_SERVER['HTTPS']) && 'on' === $_SERVER['HTTPS'] ? 'https' : 'http'; echo $scheme, '://', $_SERVER['HTTP_HOST'], $_SERVER['SCRIPT_NAME']; Almost what im looking for.. Im trying to track ppl trying to hack my site I have this in htaccess: ErrorDocument 404 /404.php , so whenever someone tries to guess urls: http://site.com/admin/something.php it will automatically go to http://site.com/404.php. But $_SERVER['HTTP_REFERER']; isnt working for this. Quote Link to comment https://forums.phpfreaks.com/topic/172107-get-url/#findComment-907425 Share on other sites More sharing options...
trq Posted August 27, 2009 Share Posted August 27, 2009 $_SERVER['HTTP_REFERER'] will get you the site the visitor came from if they clicked a link to your site. Provided of course there browser sends this information. What information are you after exactly? keep in mind that anyone who knows anything about cracking websites won't send very much real information in there requests at all. Quote Link to comment https://forums.phpfreaks.com/topic/172107-get-url/#findComment-907440 Share on other sites More sharing options...
dreamwest Posted August 27, 2009 Author Share Posted August 27, 2009 Im interested in seeing what theyre after, itll give me some insite on how to better secure the site Over the last 5 mins ive had 5 different ips trying to access restricted files, i dont want to ban them yet i want to spy on them and see what they do Quote Link to comment https://forums.phpfreaks.com/topic/172107-get-url/#findComment-907460 Share on other sites More sharing options...
trq Posted August 27, 2009 Share Posted August 27, 2009 Your server logs are probably the best things to look at. Quote Link to comment https://forums.phpfreaks.com/topic/172107-get-url/#findComment-907463 Share on other sites More sharing options...
dreamwest Posted August 27, 2009 Author Share Posted August 27, 2009 Finally figured it out # provide a universal error document RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /404.php?url=$1 [L] The just use $_GET in 404.php Quote Link to comment https://forums.phpfreaks.com/topic/172107-get-url/#findComment-907985 Share on other sites More sharing options...
DavidAM Posted August 28, 2009 Share Posted August 28, 2009 $_SERVER['REQUEST_URI'] should give you that information without having to do rewrites, I think. Quote Link to comment https://forums.phpfreaks.com/topic/172107-get-url/#findComment-908077 Share on other sites More sharing options...
dreamwest Posted August 28, 2009 Author Share Posted August 28, 2009 $_SERVER['REQUEST_URI'] should give you that information without having to do rewrites, I think. Your right. My way was getting a little buggy so i tried yours and it works. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/172107-get-url/#findComment-908161 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.