Jump to content

Detect if https then convert all urls to https


khurramalvi

Recommended Posts

Detect if https then convert all urls to https

 

Hi,

 

I am facing a big challenge with WHMCS. I installed SSL certficate and in firefox everything works fine but in IE I got annoying popup saying that this page has unsecure items.

 

I want to have function that detect that if I am on https then all links will change from http to https for e.g. http://www.domain.com/images/logo.php'>http://www.domain.com/images/logo.php to https://www.domain.com/images/logo.php'>https://www.domain.com/images/logo.php and so on.

 

This works fine when I hardcode everything but when I go out of secure path everything messed up because it calls my homepage i.e. https://www.domain.com instead http://www.domain.com

 

I found this piece of code and it doesn't work with whmcs.

 

if ($_SERVER['HTTPS']!="on") {

$url = "https://".$_SERVER["HTTP_HOST"]."/".$_SERVER["REQUEST_URI"];

header("Location: $url");

exit;

}

 

I am thinking a way around to create something like this:

 

<a href="page.php" {php if ($securepage == 'https://') { }else="http://"{php } }>

 

Thanks for your help.

Link to comment
Share on other sites

Thanks for the reply. It is fine with images but can you suggest something about unsecure links. Let me show your my website, please follow below url:

http://www.mywebhosted.com/support/

 

So all the header and footer links are unsecure for e.g. Home, Domain Registration, etc... how can I switch between secure and unsecure links?

 

Best Regards

Link to comment
Share on other sites

The message occurs when clients attempt to view a webpage using https that contains information linked using http.

 

This happens when using the full URL when linking to images or including files.

 

In the example below, the image is being linked non-securely using http.

This is what causes the error message:

 

<img src="http://yourdomain.com/images/image1.gif">

 

WHMCS keeps things fairly tidy in defined folders so its easy to ensure that links are virtual rather than direct. The folder is referenced to your root WHMCS folder.

 

So if your root WHMCS folder is http://yourdomain.com/whmcs then both these are the same:

 

Will give insecure error

<img src =http://yourdomain.com/whmcs/images/image1.gif>

 

 

This example does the same as above using a virtual link and won't give error.

<img src="/images/image1.gif">

 

To see specifically what is being called, you can either view the source of the page through the browser or click No in the error message.

 

This will load the secure portions and skip the non-secure portions. The non-secure images will be displayed as broken images and will help to narrow down which portions of the site are being loaded non-securely.

Once you isolate the cause, you will then need to adjust the code for your website to either use the https (secure) URL or a virtual link (better idea)

 

Trevor

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated