Jump to content

[SOLVED] get the 'http://' section from the url bar..


Dragen

Recommended Posts

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... ;D)

Thanks

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?

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.