Jump to content

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


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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.