We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5340
    • 1,624 Posts
    I had to do some changes to this plugin.
    This setup did not work perfectly for me.

    Instead of getting https://secure.xxxxx.com/applications/aaaaaa I was seeing https://secure.xxxxx.com/index.php?q=applications/aaaaaa.


    So I changed the code to this

    ....
    if(strtolower($_SERVER['HTTPS']) != "on" && $encryption) {
     $sUrl = explode('=',$url);
     $modx->sendRedirect($secureserver.'/'.$sUrl[1]);
    }
    


    ....

    Note: I do not think there is a need to modify the htaccess file. It should work with the one provided by modx
      • 12379
      • 460 Posts
      Does anyone know if this snippet is php5 compatible (5.2.9) ?

      A client has just upgraded their web site from php 4 to 5 and now there’s weird urls like:


      http://www.domain.com.au/index.php?q=index.html.var
      http://www.domain.com.au/index.php?q=directory/file.html

      (running Modx 0.9.6.1B)
        Mostly harmless.
        • 14491
        • 15 Posts
        I’m running php 5.2.9, and it works but I had to make a small modification (see my previous post). Please read the two posts prior to yours, I think they will solve your problem.

        Good Luck.
          • 12379
          • 460 Posts
          ’fraid not. Your hack appears to fix a https url. Mine’s just http page with the Encryption snippet enforcing http. I’ve just disable the encryption snippet from the home page but it still shows the same weird url. Maybe it’s something else, although I’ve only seen this url behaviour in Encryption’s previous release.

          BTW, my config is this:

          // CONFIGURATION SECTION ::::::::::::::::::::::::::::::::::::::::
          
          // secure location of modx installation - no trailing slash
          $secureserver = "https://www.domain.com.au";
          
          // unsecure location of modx installation - no trailing slash
          $unsecureserver = "http://www.domain.com.au";
            Mostly harmless.
            • 14491
            • 15 Posts
            So this happens even when you start from an unencrypted page? (for example, assuming your home page is unencrypted and you type http://www.domain.com.au into the browser) That would be strange as the snippet should only redirect when changing from an unencrypted to encrypted page or vice versa. If this is the case I think it’s probably something else.

            To get some more information add a few echo statements to see what is happening in the variables. I commented out the modx->sendRedirect line and then added echo $url.

            The variables will be echoed where you added the encryption snippet in the template.
              • 12379
              • 460 Posts
              Yes that’s correct - for non encrypted pages (which still have the Encryption snippet ’off’ in them).

              As for the echo statement (on an encrypted page) it revealed the identical value as the url itself.

              ie

              when typing in https://www.domain.com.au/checkout/step-1.html

              the browser url changed to https://www.domain.com.au/index.php?q=checkout/step-1.html

              and the echo statement displayed: index.php?q=checkout/step-1.html

              Maybe it’s a Modx 0.9.6.1B - php 5.2.9 incompatibility?
                Mostly harmless.
                • 29774
                • 386 Posts
                Hi

                I had problems with this snippet and PHP5 - and found that a plugin was the more reliable solution.

                It’s pretty simple. Use this custom placeholder in your template head:
                <base href="((base.href))" />

                Prepend this placeholder to links that must always point to https regardless if the page the link appears on is encrypted or not:
                ((secure.server))

                Prepend this placeholder to links that must always point to http regardless if the page the link appears on is encrypted or not:
                ((insecure.server))

                (Note that using these last two placeholders should only be necessary for forms that POST data to another page, eg login forms and search forms where you don’t want the page to redirect thus losing your POSTed data).

                Create a TV called ’encryption’, make it a checkbox and set the input option value: Yes==1

                Assign the TV to all your templates and check the checkbox for pages that will you want SSL

                Create a plugin called SSL, copy the code below into it and and tick the OnWebPageInit event.
                (Change the $secureserver and $insecureserver values to your server)

                /*
                Title:      SSL
                Author:     Mark Croxton, [email protected]
                Desc:		Plugin triggered OnWebPageInit
                			Manages switching between secure and insecure pages
                			Sets sitewide custom placeholders for secure/insecure server paths and base href
                Updated:    May 29 2009
                */
                
                global $modx;
                
                // server paths - no trailing slash!
                $secureserver 	= "https://www.mywebsite.com";
                $insecureserver = "http://www.mywebsite.com";
                
                $id = $modx->documentIdentifier;
                $tv = $modx->getTemplateVar('encryption', "", $id);
                $encryption = $tv['value']; // will be set to false if not set
                
                // What's the URI of the page we're checking
                $url = $_SERVER['REQUEST_URI'];
                
                // check for SSL
                $ssl = isSSL();
                
                // switch between http / https if necessary
                // if $secureserver === $insecureserver (eg you are testing locally) 
                // then comment out this code block to avoid infinite recursion
                if($encryption && !$ssl) {
                	// if SSL off and we are about to access a secure page then redirect
                  	$modx->sendRedirect($secureserver.$url);
                } else if ($ssl && !$encryption) {
                	// if SSL is on and we are about to acccess an unsecure page then redirect
                  	$modx->sendRedirect($insecureserver.$url);
                }
                
                // set the some globals for use in custom non-caching ((placeholders))
                if ($ssl) {
                	$GLOBALS['basehref'] = $secureserver.'/';
                } else {
                	$GLOBALS['basehref'] = $insecureserver.'/';
                }
                $GLOBALS['secureserver']   = $secureserver.'/';
                $GLOBALS['insecureserver'] = $insecureserver.'/';
                
                function isSSL(){
                	if($_SERVER['HTTPS'] == 1)  {
                     	return TRUE;
                  	} elseif ($_SERVER['HTTPS'] == 'on'){
                     	return TRUE;
                  	} elseif ($_SERVER['SERVER_PORT'] == 443) {
                     	return TRUE;
                  	} else {
                  		return FALSE;
                  	}
                }
                
                


                Now create a second plugin called SSL-PH with the code below and check the OnWebPagePrerender event.

                /*
                Title:      SSL PH
                Author:     Mark Croxton, [email protected]
                Desc:		Plugin triggered OnWebPagePrerender
                			Replaces custom SSL placeholders in the document output
                Updated:    May 29 2009
                */
                
                global $basehref, $secureserver, $insecureserver;
                $fields = array('((base.href))','((secure.server))','((insecure.server))');
                $values = array($basehref, $secureserver, $insecureserver);
                $modx->documentOutput = str_replace($fields,$values,$modx->documentOutput);
                


                Edited: 7th August 2009 - revised version sets global variables $GLOBALS[’secureserver’] and $GLOBALS[’insecureserver’] which can also be accessed in snippets
                  Snippets: GoogleMap | FileDetails | Related Plugin: SSL
                  • 14491
                  • 15 Posts
                  therebechips, this looks like a more elegant solution than a snippet, good work. I’ll try this next time I need encryption.
                    • 13428 ☆ A M B ☆
                    • 1,031 Posts
                    Maybe the plugin should be published in the repository. It’s a bit hidden here at the end of a support thread for a similar but half comfortable snippet.
                      • 29774
                      • 386 Posts
                      Good point - I’ve submitted SSL to the repository, hopefully it will appear there soon.
                        Snippets: GoogleMap | FileDetails | Related Plugin: SSL