Jump to content

HTTP 500 Error when switching language


cracked

Recommended Posts

Hello dear Devs,

 

we have a problem lasting several months now, and have been ignoring it so far as it doesn't occur very often.

When you switch the language in prestashop the page won't load, instead displaying you a HTTP 500-Server Error page. After that you can reload the page and it comes up normally like it should.

 

This happens every single time you switch the language! 100% reproducible.

Well now the funny part starts, as I just found out while writing a new script for a prestashop module, which doesn't use ANY prestashop functions so far, suddenly it shows the same behaviour. And its related to the language switching again.

 

So I tried to nail it down and came up with this test-script:

<?php
/* include these prestashop files and the server will crash when setlocale-switch occurs */
include_once(dirname(__FILE__).'/config/config.inc.php');
include_once(dirname(__FILE__).'/init.php');


class Testclass
{
public function test()
{
if (isset($_GET['id_lang'])) $id_lang = intval($_GET['id_lang']);
echo "using id_lang: ".$id_lang;

if ($id_lang == 2) setlocale(LC_TIME, 'de_DE.utf8');
else setlocale(LC_TIME, 'en_US.utf8');

echo strftime('%B', mktime(0, 0, 0, 3, 1));
}

}

Testclass::test();

As soon as you include prestashops config.inc.php and init.php you'll see this error (Tested on 3 (!) different machines, with even slightly different setups), obviously you'll have to change the parameter 

 

script.php?id_lang=1 

 

to

 

script.php?id_lang=2 

 

 

Any ideas why this happens?

Is this the case for you too?

PS: Make sure the locales used in this script are installed on your server. For us they can be used without any problems, other than this one described here.

Regards,

Lennart

Edited by cracked (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Hello,

 

I've same problem with my shop.

For me the problem appear when create new language, the admin doesn't set all required data in database. 

 

Check table lang has all field complete specially locale

 

I hope this reply help you.

Link to comment
Share on other sites

  • 1 month later...

Hello, 

 

I have the same problem. When I switch language the website gives me the HTTP 500 error and I have to clear the browsers cache and cookies to be able to access the website again.

 

Any solutions? :(

Link to comment
Share on other sites

Hi guys, 

in our specific case the error log of the server shows, that this problem lies within a module called "Advanced SEO Friendly URLs Module" or "fsadvancedurl".

https://addons.prestashop.com/en/url-redirects/19643-advanced-seo-friendly-urls.html
 

I just can highly recommend to check the apache error log, as when a HTTP 500 Server Error occurs you don't get to see any output in your browser. 

 

So again, in our case the log shows the following:

 

AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to a member function registerPlugin() on null in /var/www/vhosts/my-lab.com/httpdocs/analytics/config/smarty.config.inc.php:185\nStack trace:\n#0 /var/www/vhosts/my-lab.com/httpdocs/analytics/modules/fsadvancedurl/classes/FsAdvancedUrlModule.php(72): smartyRegisterFunction(NULL, 'modifier', 'fsauCorrectTheM...', 'unescapeSmarty')\n#1 /var/www/vhosts/my-lab.com/httpdocs/analytics/modules/fsadvancedurl/fsadvancedurl.php(72): FsAdvancedUrlModule->__construct()\n#2 [internal function]: Fsadvancedurl->__construct()\n#3 /var/www/vhosts/my-lab.com/httpdocs/analytics/Core/Foundation/IoC/Core_Foundation_IoC_Container.php(124): ReflectionClass->newInstance()\n#4 /var/www/vhosts/my-lab.com/httpdocs/analytics/Core/Foundation/IoC/Core_Foundation_IoC_Container.php(157): Core_Foundation_IoC_Container->makeInstanceFromClassName('fsadvancedurl', Array)\n#5 /var/www/vhosts/my-lab.com/httpdocs/analytics/Core/Foundation/IoC/Core_Foundation_IoC_Container.php(170): Core_Foundation_I...\n', referer: https://my-lab.com/analytics/en/my-food/

 

 

So this proves that this module is responsible for the server error. Apparently it hooks so deep to prestashops core, that it can even crash my test-script on language switching, even when it's just including prestashops init.php.

 

I have to say: impressive!

 

Regards

Edited by cracked (see edit history)
Link to comment
Share on other sites

  • 6 months later...

I found a solution for this problem as well:

 

If smartyRegisterFunction is bringing this or a similar output to your apache error log (resulting in HTTP Error 500) then try this fix:

Modify /config/smary.config.inc.php like this:

function smartyRegisterFunction(&$smarty, $type, $function, $params, $lazy = true)
{
    if (!in_array($type, array('function', 'modifier', 'block'))) {
        return false;
    }

    if(is_null($smarty)) $smarty = $GLOBALS['smarty'];
    if(is_null($smarty)) return false;

 

Just return false if there is no "$smarty". Works like a charm.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...