xavibj Posted April 3, 2017 Share Posted April 3, 2017 Hi, if I try to execute the following script <?php include_once('/var/ean/config/config.inc.php'); include_once('/var/ean/init.php'); $p = new Product(401); echo $p->id; ?> in a prestahop site with "all pages SSL" enabled fails with these warnings: PHP Notice: Undefined index: REQUEST_METHOD in /home/ean_test/classes/controller/FrontController.php on line 788 Notice: Undefined index: REQUEST_METHOD in /home/ean_test/classes/controller/FrontController.php on line 788 PHP Warning: Cannot modify header information - headers already sent by (output started at /home/ean_test/classes/controller/FrontController.php:788) in /home/ean_test/classes/controller/FrontController.php on line 790 Warning: Cannot modify header information - headers already sent by (output started at /home/ean_test/classes/controller/FrontController.php:788) in /home/ean_test/classes/controller/FrontController.php on line 790 PHP Warning: Cannot modify header information - headers already sent by (output started at /home/ean_test/classes/controller/FrontController.php:788) in /home/ean_test/classes/controller/FrontController.php on line 791 Warning: Cannot modify header information - headers already sent by (output started at /home/ean_test/classes/controller/FrontController.php:788) in /home/ean_test/classes/controller/FrontController.php on line 791 PHP Warning: Cannot modify header information - headers already sent by (output started at /home/ean_test/classes/controller/FrontController.php:788) in /home/ean_test/classes/controller/FrontController.php on line 793 Warning: Cannot modify header information - headers already sent by (output started at /home/ean_test/classes/controller/FrontController.php:788) in /home/ean_test/classes/controller/FrontController.php on line 793 the problem is in the if condition in sslRedirection, that evaluates to true. protected function sslRedirection() { // If we call a SSL controller without SSL or a non SSL controller with SSL, we redirect with the right protocol if (Configuration::get('PS_SSL_ENABLED') && $_SERVER['REQUEST_METHOD'] != 'POST' && $this->ssl != Tools::usingSecureMode()) { $this->context->cookie->disallowWriting(); header('HTTP/1.1 301 Moved Permanently'); header('Cache-Control: no-cache'); if ($this->ssl) { header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']); } else { header('Location: '.Tools::getShopDomain(true).$_SERVER['REQUEST_URI']); } exit(); } } To solve this error I added isset($_SERVER['REQUEST_METHOD']) to the condition to avoid entering when called from external scripts and now all of them work again. is it correct? any thoughts? Thanks, Xavi. Link to comment Share on other sites More sharing options...
jokerstar Posted July 22, 2017 Share Posted July 22, 2017 Hi, I installed ssl on whole page and got same error when using cron. I tried your fix but it only fix : PHP Notice: Undefined index: REQUEST_METHOD in /home/ean_test/classes/controller/FrontController.php on line 788 Notice: Undefined index: REQUEST_METHOD in /home/ean_test/classes/controller/FrontController.php on line 788 I still got problem with lines 790 791 793 PHP Warning: Cannot modify header information - headers already sent by (output started at /home/ean_test/classes/controller/FrontController.php:788) in /home/ean_test/classes/controller/FrontController.php on line 790 Warning: Cannot modify header information - headers already sent by (output started at /home/ean_test/classes/controller/FrontController.php:788) in /home/ean_test/classes/controller/FrontController.php on line 790 PHP Warning: Cannot modify header information - headers already sent by (output started at /home/ean_test/classes/controller/FrontController.php:788) in /home/ean_test/classes/controller/FrontController.php on line 791 Warning: Cannot modify header information - headers already sent by (output started at /home/ean_test/classes/controller/FrontController.php:788) in /home/ean_test/classes/controller/FrontController.php on line 791 PHP Warning: Cannot modify header information - headers already sent by (output started at /home/ean_test/classes/controller/FrontController.php:788) in /home/ean_test/classes/controller/FrontController.php on line 793 How you fix this? Link to comment Share on other sites More sharing options...
bellini13 Posted July 23, 2017 Share Posted July 23, 2017 why are you including this? include_once('/var/ean/init.php'); Your script is not a front controller, what exactly is the intention of this script? Link to comment Share on other sites More sharing options...
jokerstar Posted July 23, 2017 Share Posted July 23, 2017 its xml import script. hmm so not needed init in this case? Link to comment Share on other sites More sharing options...
bellini13 Posted July 24, 2017 Share Posted July 24, 2017 did you bother to try? Link to comment Share on other sites More sharing options...
jokerstar Posted July 25, 2017 Share Posted July 25, 2017 i tried it and it works without init.php and also works with this edit: if (Configuration::get('PS_SSL_ENABLED') && $_SERVER['REQUEST_METHOD'] != 'POST' && $this->ssl != Tools::usingSecureMode()) { both works OK Link to comment Share on other sites More sharing options...
bellini13 Posted July 26, 2017 Share Posted July 26, 2017 but if you are not creating a FrontController (aka a page on your website), then you would not use init.php Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now