Jump to content

External PHP scripts with All pages SSL enabled


xavibj

Recommended Posts

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

  • 3 months later...

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

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

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...