Dragen Posted September 16, 2007 Share Posted September 16, 2007 Hi, I'm sure this is really simple, but I'm trying to get the full url from the address bar. I'm using this: $url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; which works fine except I'm wanting to check whether the page is 'http://', 'https://' or even 'ftp://' and add that to the beginning. At the moment I get something like: www.mydomain.com/folder/index.php Can anyone help me get the protocol? (I think that's what it's called... ) Thanks Quote Link to comment https://forums.phpfreaks.com/topic/69553-solved-get-the-http-section-from-the-url-bar/ Share on other sites More sharing options...
rarebit Posted September 16, 2007 Share Posted September 16, 2007 You could try $_SERVER['SERVER_PROTOCOL'], test the variations though, it's not quite what you want but you'll see! Quote Link to comment https://forums.phpfreaks.com/topic/69553-solved-get-the-http-section-from-the-url-bar/#findComment-349500 Share on other sites More sharing options...
Dragen Posted September 16, 2007 Author Share Posted September 16, 2007 ah thanks! seems pretty much what I need. I can't test it much as I don't have access to a secure server for testing https or a ftp server, but running through http gives me 'http/1.1'. Do you know if it always outputs the protocol name followed by a slash and revision number? Quote Link to comment https://forums.phpfreaks.com/topic/69553-solved-get-the-http-section-from-the-url-bar/#findComment-349503 Share on other sites More sharing options...
rarebit Posted September 16, 2007 Share Posted September 16, 2007 Yes it does (it's the protocol), but it doesn't change when it's https, you need to check for it using: if (strcmp($_SERVER['HTTPS'], 'on')==0) { print "HTTPS is ON<br>"; } Not checked ftp yet... Quote Link to comment https://forums.phpfreaks.com/topic/69553-solved-get-the-http-section-from-the-url-bar/#findComment-349509 Share on other sites More sharing options...
Dragen Posted September 16, 2007 Author Share Posted September 16, 2007 thanks. I actually just looked up $_SERVER['HTTPS'] and found this on php.net.. echo sprintf('http%s://%s%s', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE ? 's': ''), $_SERVER['HTTP_HOST'] , $_SERVER['REQUEST_URI']); Which works great. I'm forgetting about ftp, because no-one should really be using it for my code anyway. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/69553-solved-get-the-http-section-from-the-url-bar/#findComment-349512 Share on other sites More sharing options...
Daniel0 Posted September 16, 2007 Share Posted September 16, 2007 I'm forgetting about ftp, because no-one should really be using it for my code anyway. Well, FTP servers cannot run PHP scripts, so you couldn't possibly use it for anything. Quote Link to comment https://forums.phpfreaks.com/topic/69553-solved-get-the-http-section-from-the-url-bar/#findComment-349517 Share on other sites More sharing options...
Dragen Posted September 16, 2007 Author Share Posted September 16, 2007 hehe fair enough.. to be honest I've never mucked about with ftp servers so I didn't know whether they could or not.. Quote Link to comment https://forums.phpfreaks.com/topic/69553-solved-get-the-http-section-from-the-url-bar/#findComment-349518 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.