We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26016
    • 561 Posts
    Hi All,
    I just was asked to move a site to Namecheap hosting. I like their domain hosting and use it myself, but this is my first time with their web hosting. It's basically decent, with a CPanel interface. I got the site installed and running.

    Then the fun started. I wanted to edit a snippet for a filepath. It saved the snippet, but with all kinds of extra backslashes. No big deal, I'd seen this, it's simply a very out-of-date dumb PHP setting,
    magic_quotes_gpc


    But putting a command to shut that off in php.ini did not do anything for that except cause a PHP date error. I checked it out and found that PHP 5.3 needs timezone to be set. Added that to php.ini, same date error.

    I tried moving php.ini it to the /manager folder, and that knocked me out of the manager entirely.

    I even tried sticking the kill quotes command in .htaccess - that flavor didn't work, either, killed the site completely.

    I tried editing the snippet via the database, but then I got a parsing error when running the snippet due to a double-quote.

    At this point, I'll ask if they will shut magic_quotes off at the server level and see if that works. Also, they apparently will run PHP 5.2 if asked, though I wonder if they'll still have the stupid quotes setting there.

    I know it's unlikely that someone will have a magic bullet for this, just wanted to raise awareness about Namecheap web hosting, which is a little bit funky.

    Cheers, Dave [ed. note: samba last edited this post 14 years, 8 months ago.]
      MODx and Wordpress development
      Linux, PHP 5.2, MySQL 5.0, Evo 1.05, Revo 2.08-pl, Firefox 4
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      If you use custom php.ini files within the site, you have to have one for every directory that runs a .php file. That means you have to have one in the /manager/ folder, and should have one in the site's root as well. MODx by itself only runs the two index.php files; all the rest are included by those two, one for the front-end and one for the manager. The magic_quotes problem is not an issue in the front-end unless you have snippets that save stuff to the database from front-end forms.

      The technically correct way to have a custom php.ini file is to have a copy of the main php.ini file and then edit that to set your custom values.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 26016
        • 561 Posts
        Thanks for the reply, Susan.

        Yes, as I said above, I did try using php.ini in both folders, no good. AFAIK, I have no access to their php.ini. I don't doubt what you're saying about having a copy of php.ini, but I've never had trouble overriding and adding single commands on good hosts.

        Thanks for info about the front-end, which is what I had guessed. In any case, the site is a rat's nest for the time being. If I have trouble after investigating this far, less nerdy people will have a miserable time there. I'll report if I get some help from Namecheap support.
          MODx and Wordpress development
          Linux, PHP 5.2, MySQL 5.0, Evo 1.05, Revo 2.08-pl, Firefox 4
          • 26016
          • 561 Posts
          OK! Success, after 2 tries with their "helpful" tech support.

          This line in .htaccess brought us down to PHP 5.2:
          AddHandler application/x-httpd-php52 .php


          The rest was up to me. I had already tried all else that they suggested. Instead, I wrote a plugin to fix the damn thing on-the-fly. The plugin fires on this event: OnSnipFormSave

          That way it's not running on every little database request. It may need to be used with other events in some situations, but I was concentrating on getting snippet editing to work.

          ... and here's the code, which I cadged from php.net. Note that I've removed the usual beginning and ending PHP tags. I haven't written a MODx plugin in quite some time, so I forgot this.

          if (get_magic_quotes_gpc()) {
              $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
              while (list($key, $val) = each($process)) {
                  foreach ($val as $k => $v) {
                      unset($process[$key][$k]);
                      if (is_array($v)) {
                          $process[$key][stripslashes($k)] = $v;
                          $process[] = &$process[$key][stripslashes($k)];
                      } else {
                          $process[$key][stripslashes($k)] = stripslashes($v);
                      }
                  }
              }
              unset($process);
          }


          So now I can edit snippets without stupid extra slashes showing up. For yucks I tried the same code in PHP 5.3, and it didn't work. Some better coder than me could probably pull that off.

          So the moral is.... Namecheap hosting does not like MODx Evo all that much, but it will reluctantly accept it. A similar strategy could be used for Revo, I think.

          I am not too impressed with the Namecheap tech support, not to mention the dopeyness of having magic quotes on and not being sensible enough to turn that off at the server level. I'll mention this on my blog. smiley [ed. note: samba last edited this post 14 years, 8 months ago.]
            MODx and Wordpress development
            Linux, PHP 5.2, MySQL 5.0, Evo 1.05, Revo 2.08-pl, Firefox 4