Results 1 to 16 of 16
  1. #1
    Join Date
    May 2010
    Posts
    40

    WHMCS 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 to 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.

  2. #2
    Join Date
    Apr 2009
    Location
    Bangladesh
    Posts
    406
    do you have ssl installed on your whole website (all subdomains) ? If you don't then its not a good idea to use https for them. When the user will try to access with https on a non-https page, he/she will get an error.

    If you do have https for all your pages, then why do you need to change the links to https only when user is on https ? You can edit the WHMCS templates and change the links to https permanently. You don't need to use php for that.

    If you still want to do what you're trying to do, then ask again and I'll help.
    Sajid Iftekhar - Web Design Portfolio

  3. #3
    Join Date
    May 2010
    Posts
    40
    Hi Sajid213,

    Thanks very much for the reply. I really want to do in my way. I think you will good picture of my situation after visitng my website:

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

    So All header and footer links are http and they remain http even in https url i.e. order form

    ============
    http urls
    ============
    Home
    Domain Registration
    Domain Reseller
    etc...

    ============
    https form
    ============
    https://www.mywebhosted.com/support/order/?pid=1&skip=1

    If somehow I can manage to get header and footer links i.e. Home, Domain Registration, Domain Reseller in https when I am in secure url then it will be great and I will get rid of IE annoying message.

    Another problem is after converting http link into https if customer clicks any of unsecure page and it is https then they will remain in secure url even page is static.

    It will be great if somehow I can force everything to be https in secure location and http in unsecure location.

  4. #4
    Join Date
    Apr 2009
    Location
    Bangladesh
    Posts
    406
    Ok I think i understand. This code is untested, so it might not work as expected:
    HTML Code:
    <a href="{php}echo ($_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://');{/php}mydomain.com/page.php">
    Try it out and let me know if it works. If it doesn't work, I'll try it out on my whmcs
    Sajid Iftekhar - Web Design Portfolio

  5. #5
    Join Date
    May 2010
    Posts
    40
    Thanks, I will try that and update you soon.

  6. #6
    Join Date
    May 2010
    Posts
    40
    Wow, works great. I have done some customization in my root .htaccess file to force all unsecure urls to http even if it https.

    Code:
    RewriteCond %{HTTP_HOST} \.
    RewriteCond %{HTTP_HOST} !^www\.mywebhosted\.com [NC]
    RewriteRule (.*) http://www.mywebhosted.com/$1 [R=301,L]
    
    RewriteCond %{SERVER_PORT} !^80$
    RewriteRule (.*) http://www.mywebhosted.com/$1 [R=301,L]
    Just one thing and script will be perfect. Is that possible to define url function and call that function instead of repeating full url each time for e.g.

    Code:
    <a href="{php}echo ($_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://');{/php}www.mywebhosted.com/domain-registration.php">
    To be relative

    Code:
    <a href="{php}echo ($_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://');{/php}../domain-registration.php">
    I found this code but dont know how to use it properly.

    if ($_SERVER['HTTPS'] != "on") {
    $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    header("Location: $url");
    exit;
    }

    Thanks

  7. #7
    ^thanks for posting that!

  8. #8
    Join Date
    Apr 2009
    Location
    Bangladesh
    Posts
    406
    No, if you use the http/https protocols, your URLs must be absolute. If you want to make things easier, maybe you can try this code. Again, I'm not sure if it will work since its untested.

    Go to your WHMCS template's header.tpl file and at the very top, put this:
    PHP Code:
    {php}
    $p = ($_SERVER['SERVER_PORT'] == 443 'https' 'http');
    $url $p.'://www.mywebhosted.com/'// This is the url of your main site
    $whmcs $p.'://www.mywebhosted.com/support/'// This is the url of your whmcs folder
    {/php
    So, now instead of putting that long piece of code you can you can put this instead:
    HTML Code:
    <a href="{php}echo $url;{/php}page_of_main_site.php">
    OR
    HTML Code:
    <a href="{php}echo $whmcs;{/php}clientarea.php">
    Been a long time since I did some coding. Feels really good to get back into php .If you have any more questions, let me know .


    Edit:
    I found this code but dont know how to use it properly.

    if ($_SERVER['HTTPS'] != "on") {
    $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    header("Location: $url");
    exit;
    }
    You don't need that. It won't do what you are trying to do. The code I posted will work better.
    Sajid Iftekhar - Web Design Portfolio

  9. #9
    Join Date
    Apr 2011
    Location
    Leicester, UK
    Posts
    16
    I have raised the very same issue with WHMCS but they didn't understand what I meant even though I have taken screenshots of the errors. I wouldn't of minded if I had integrated my template into WHMCS as it would of been my mistake, but I paid them to do it and get the IE error saying that the security of the web page is going to be compromised as some parts of the page are unsecure. I will try your code in the morning Sajid213 and let you know how I get on. Thanks for this.

  10. #10
    Join Date
    Jun 2003
    Location
    Sheffield
    Posts
    810
    pwh-Kieran: Please advise the Ticket ID and I'll see what I can find.
    WHMCS
    The Complete Client Management, Billing & Support System
    Documentation | Help Guides

  11. #11
    Join Date
    Apr 2011
    Location
    Leicester, UK
    Posts
    16
    Hello Chickndip, Thank you for replying. I think I have resolved this issue myself now. But if you still wish to take a look at the Ticket then the ID is 927951.

  12. #12
    Join Date
    Apr 2009
    Location
    Bangladesh
    Posts
    406
    Quote Originally Posted by pWh-Kieran View Post
    Hello Chickndip, Thank you for replying. I think I have resolved this issue myself now. But if you still wish to take a look at the Ticket then the ID is 927951.
    Great. If you still have any issues, just post here
    Sajid Iftekhar - Web Design Portfolio

  13. #13
    Join Date
    Apr 2011
    Location
    Leicester, UK
    Posts
    16
    I will do chickndip, thanks for your assistance. I presume your part of the WHMCS Support & Services team?

  14. #14
    Join Date
    Jun 2003
    Location
    Sheffield
    Posts
    810
    OK I'm glad to hear you were able to get the issue sorted, there isn't much for me to look at in that case.
    I'm not a member of the services team, but I do work for WHMCS.
    WHMCS
    The Complete Client Management, Billing & Support System
    Documentation | Help Guides

  15. #15
    Join Date
    May 2010
    Posts
    40
    Sorry haven't got time. I will try your enhanced code and update the thread.
    Last edited by khurramalvi; 04-21-2011 at 01:59 PM.

  16. #16
    Join Date
    May 2010
    Posts
    40
    Sajid213 you are star man. Just one thing I have to put {php} twice, h eader and footerotherwise it takes whmcs path.

    http://www.mywebhosted.com/support

    Any advice.



    Quote Originally Posted by sajid213 View Post
    No, if you use the http/https protocols, your URLs must be absolute. If you want to make things easier, maybe you can try this code. Again, I'm not sure if it will work since its untested.

    Go to your WHMCS template's header.tpl file and at the very top, put this:
    PHP Code:
    {php}
    $p = ($_SERVER['SERVER_PORT'] == 443 'https' 'http');
    $url $p.'://www.mywebhosted.com/'// This is the url of your main site
    $whmcs $p.'://www.mywebhosted.com/support/'// This is the url of your whmcs folder
    {/php
    So, now instead of putting that long piece of code you can you can put this instead:
    HTML Code:
    <a href="{php}echo $url;{/php}page_of_main_site.php">
    OR
    HTML Code:
    <a href="{php}echo $whmcs;{/php}clientarea.php">
    Been a long time since I did some coding. Feels really good to get back into php .If you have any more questions, let me know .


    Edit:


    You don't need that. It won't do what you are trying to do. The code I posted will work better.

Similar Threads

  1. https iframe in https page question
    By diesel12 in forum Web Design and Content
    Replies: 0
    Last Post: 11-04-2010, 03:21 PM
  2. Https or not?
    By bambinou in forum Ecommerce Hosting & Discussion
    Replies: 21
    Last Post: 09-11-2009, 06:17 PM
  3. Force HTTPS on WHMCS
    By HostedPlanet in forum Hosting Software and Control Panels
    Replies: 5
    Last Post: 09-09-2009, 04:08 PM
  4. SSL on https://domain.com vs https://www.domain.com
    By sbogde in forum Hosting Security and Technology
    Replies: 3
    Last Post: 10-02-2007, 05:40 AM
  5. HTTPS URLs
    By alex-info in forum Web Hosting
    Replies: 14
    Last Post: 11-07-2003, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •