We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17016
    • 138 Posts
    OK, our error log works again (the file was too big an had to be manually cleared ):

    The output of the error log after calling the snippet via a ssl-page or a 404-error:

    [2010-12-09 19:05:16] (ERROR @ /index.php) Testing: 1
    [2010-12-09 19:05:18] (ERROR @ /index.php) Testing: 1
    [2010-12-09 19:05:41] (ERROR @ /index.php) Testing: adsfasdfadsfsadf
    [2010-12-09 19:05:46] (ERROR @ /index.php) Testing: 1
    [2010-12-09 19:05:49] (ERROR @ /index.php) Testing: 1
    [2010-12-09 19:06:03] (ERROR @ /index.php) Testing: 794
    [2010-12-09 19:06:05] (ERROR @ /index.php) Testing: 1
    [2010-12-09 19:06:08] (ERROR @ /index.php) Testing: 460
    [2010-12-09 19:06:09] (ERROR @ /index.php) Testing: 460
    [2010-12-09 19:06:09] (ERROR @ /index.php) [OnWebPageInit]1
    [2010-12-09 19:06:21] (ERROR @ /index.php) Testing: 1
    [2010-12-09 19:06:25] (ERROR @ /index.php) Testing: 460
    [2010-12-09 19:06:25] (ERROR @ /index.php) [OnWebPageInit]1
    [2010-12-09 19:06:32] (ERROR @ /index.php) Testing: 1

    In summary the plugin works very well with the exception of the 404-error-page which redirects to the startpage instead of the predefined error-page.
      • 5340
      • 1,624 Posts
      Let’s try excluding those pages from the SSL plugin.
      I assume that all the 401 page don’t have a proper ID so let’s detect if the identifier is an integer.


      using MadeMyDay code
      
      if ($modx->event->name == 'OnWebPageInit') { 
      	//CONFIGURATION
      	// server paths - no trailing slash!
      	$secureserver = "https://fgm-factoring.de";
      	$insecureserver = "http://fgm-factoring.de";
      	$resourceId = $modx->resourceIdentifier;
      	
      	if ( intval($resourceId) ){ //exclude if not an id
      	
      		
      		$encryption = FALSE;
      		$urlType = 'http';
      		$doc = $modx->getObject('modResource', $resourceId);
      		$secure = $doc->getTVValue('encryption'); 
      		if($secure=='1') {
      			$encryption = TRUE;
      			$urlType = 'https'; 
      			} 
      		$modx->setPlaceholder('urlType',$urlType);
      		$url = $_SERVER['REQUEST_URI'];
      		$ssl = FALSE;
      		if($_SERVER['HTTPS'] == 1)  {
      			    $ssl =  TRUE;
      		} elseif ($_SERVER['HTTPS'] == 'on'){
      			    $ssl =  TRUE;
      		} elseif ($_SERVER['SERVER_PORT'] == 443) {
      			$ssl = TRUE;
      		}
      		 
      		// 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);
      		}
      		
      	}//exclude if not an id
      }
      
      
        • 17016
        • 138 Posts
        Hi cipa,

        the code works and the 404-page works, too. Very good!

        But unfortunately using the improved plugin we got thousands of errors in our error-log leading to crash down of our server because of RAM-Overload while many people went to our page at the same time (directly after a Newsletter-Send-Out with links to our webpage).

        The Errors were mostly of this type:

        (ERROR @ /server/modx/core/xpdo/cache/xpdocachemanager.class.php : 413) PHP warning: unlink(/server/modx/core/cache/objects/modTemplateVarResource/2c3468c42bcf1c299e5839accdace0ea.cache.php) [<a href=’function.unlink’>function.unlink</a>]: No such file or directory

        (ERROR @ /server/modx/core/xpdo/cache/xpdocachemanager.class.php : 421) PHP warning: closedir(): 413 is not a valid Directory resource


        We also get these errors without using the ssl-plugin but in a very less number which is normally no problem for our server. Unfortunately we have no idea how we can figure out what could be the reason for this error...
          • 5340
          • 1,624 Posts
          Hi Letti,

          A quick dirty fix would be changing

          if (unlink($path)) {

          to

          if (@unlink($path)) {

          and

          closedir($handle);

          to

          @closedir($handle);


          You should also open a bug for this and point to this post. Maybe the developers can do something for the future versions

            • 17016
            • 138 Posts
            Thanks a lot. The error-messages stopped. And it seems like the error-messages of this type which were also produced (in a less number) without the ssl-plugin disappeared, too. So it seems like this bug also made problems in other areas of MODx or maybe in combination with other plugins/snippets.

            Can you explain shortly what is the function of @ (which you added in your last post) in this case?

            Now we will watch in the next hours if the problem disappears completely (hope so)...

            Thanks a lot again!!
              • 5340
              • 1,624 Posts
                • 17016
                • 138 Posts
                Thank you very much!

                I have read the explanations on the recommended site but I didn´t understand if @ stops only the error-reporting or does @ also stop the script at this point?

                Do you think we now can use the ssl-plugin with the @ without having problems or will we still have the same problems of RAM-overload?

                  • 21838
                  • 284 Posts
                  You shouldn’t use @ error suppressing anywhere. It only doesn’t output a error message but the error still is there! If an PHP error occurs you have to update your code doing the right not the server accepting it.
                    MODX Free Template Base: MODX-Boilerplate | my blog (lots of MODX stuff) | my gitHub (translations) | MODX User Groups Germany (Facebook)
                    • 22446
                    • 181 Posts
                    What is the final code for this plugin?
                      • 3186 ☆ A M B ☆
                      • 279 Posts
                      I have made this from the above code. This is working for me!

                      if($modx->event->name == 'OnLoadWebDocument') {
                         
                          $encryption_value = $modx->resource->getTVValue('encryption');
                          
                          //finally the value
                          $encryption = false;
                          if($encryption_value == 1){
                            $encryption = true;
                          }
                          
                          $ssl = false;
                          if($_SERVER['HTTPS'] == 1)  {
                            $ssl = true;
                          }
                          elseif($_SERVER['HTTPS'] == 'on'){
                            $ssl = true;
                          }
                          elseif($_SERVER['SERVER_PORT'] == 443) {
                            $ssl = true;
                          }
                         
                          // 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 SSL is on and we are about to acccess an unsecure page then redirect
                          if($ssl && !$encryption) {
                           
                            $url = $modx->makeUrl($modx->resource->get('id'), '', '', 'http');
                            $modx->sendRedirect($url);
                          }
                          // if SSL off and we are about to access a secure page then redirect
                          else if(!$ssl && $encryption) {
                           
                            $url = $modx->makeUrl($modx->resource->get('id'), '', '', 'https');
                            $modx->sendRedirect($url);
                          }
                        }


                      I hope it works for you!
                        MODX Ambassador (NL) & Professional MODX developer
                        Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
                        MODX e-commerce solution SimpleCart