AlanFan Posted August 8, 2016 Share Posted August 8, 2016 (edited) Hi , I want (A.php not on my localhost is external) post some data like order_id to change the orderstatus . When I post from external server to My Strore sever's page(B.php) Can't include config.inc.php Ex: A.php will post Array(1,2,3,4.............) to B.php I set post url= http://MyServerIp:port/prestashop/modules/B.php B.php <?php $result=$_POST; include_once(dirname(__FILE__) . '/../../config/config.inc.php'); include_once(dirname(__FILE__) . '/../../init.php'); include_once(dirname(__FILE__) . '/../../classes/order/Orde'); include_once(dirname(__FILE__) . '/../../classes/order/OrderHistory.php'); echo $result; ?> when I post but can't echo $result becuase die in include_once(dirname(__FILE__) . '/../../config/config.inc.php'); and php's errorlog no error but he didn't go to next code But when I # include can work like this <?php $result=$_POST; //include_once(dirname(__FILE__) . '/../../config/config.inc.php'); I find mark this can work but I need below class so I can't mark Config.inc.php and below's //include_once(dirname(__FILE__) . '/../../init.php'); //include_once(dirname(__FILE__) . '/../../classes/order/Orde'); //include_once(dirname(__FILE__) . '/../../classes/order/OrderHistory.php'); echo $result; ?> and also work when I just F5 B.php on my localhost do not use post <?php //$result=$_POST; $result='1234'; include_once(dirname(__FILE__) . '/../../config/config.inc.php'); include_once(dirname(__FILE__) . '/../../init.php'); include_once(dirname(__FILE__) . '/../../classes/order/Orde'); include_once(dirname(__FILE__) . '/../../classes/order/OrderHistory.php'); echo $result; ?> How can I fix it? I find the question same https://www.prestashop.com/forums/topic/375109-require-configincphp-doesnt-work-and-load-homepage-instead/ Edited August 8, 2016 by AlanFan (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 You have an error on line 6: include_once(dirname(__FILE__) . '/../../classes/order/Orde'); This should be: include_once(dirname(__FILE__) . '/../../classes/order/Order.php'); Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 That is my type mistake, but not error for this question Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 My version is 1.6.1.6 Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 I think there's no need to include init.php, since I didn't include it when I wrote ajax.php in my module. Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 I think there's no need to include init.php, since I didn't include it when I wrote ajax.php in my module. I try but not work .. Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 I just created test.php inside one of my modules on my PrestaShop v1.6.1.6 test site with your code and it worked perfectly: <?php $result=$_POST; include_once(dirname(__FILE__) . '/../../config/config.inc.php'); include_once(dirname(__FILE__) . '/../../init.php'); include_once(dirname(__FILE__) . '/../../classes/order/Order.php'); include_once(dirname(__FILE__) . '/../../classes/order/OrderHistory.php'); echo $result; ?> I see the following result: Array You should use var_dump($result); if you want to see inside the array. There must be an error in one of your included files. Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 I just created test.php inside one of my modules on my PrestaShop v1.6.1.6 test site with your code and it worked perfectly: <?php $result=$_POST; include_once(dirname(__FILE__) . '/../../config/config.inc.php'); include_once(dirname(__FILE__) . '/../../init.php'); include_once(dirname(__FILE__) . '/../../classes/order/Order.php'); include_once(dirname(__FILE__) . '/../../classes/order/OrderHistory.php'); echo $result; ?> I see the following result: Array You should use var_dump($result); if you want to see inside the array. There must be an error in one of your included files. can you try this ~ <?php session_start(); $_SESSION['POST']=$_POST; include_once(dirname(__FILE__) . '/../../config/config.inc.php'); //include_once(dirname(__FILE__) . '/../../init.php'); include_once(dirname(__FILE__) . '/../../classes/order/OrderHistory.php'); include_once(dirname(__FILE__) . '/../../classes/order/Order.php'); $file_name = date('Ymd', time()) . '.txt'; $file = dirname(__FILE__)."/log/". $file_name; $fp = fopen($file, 'a'); fwrite($fp,"\r\n". 'no die'."\r\n"); fwrite($fp, print_r($_SESSION['POST'], true)); fclose($fp); ?> Even not go to this page.. But when I mark include config.inc and can work Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 At first, I got an error that the log file didn't exist. After creating the log file and running the code, the following appeared in the log file: no die Array ( ) Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 (edited) When I do this and go to another computer to Post this page I can got $_POST and Log <?php session_start(); $_SESSION['POST']=$_POST; /* include_once(dirname(__FILE__) . '/../../config/config.inc.php'); include_once(dirname(__FILE__) . '/../../init.php'); include_once(dirname(__FILE__) . '/../../classes/order/OrderHistory.php'); include_once(dirname(__FILE__) . '/../../classes/order/Order.php'); */ $file_name = date('Ymd', time()) . '.txt'; $file = dirname(__FILE__)."/log/". $file_name; $fp = fopen($file, 'a'); fwrite($fp,"\r\n". 'no die'."\r\n"); fwrite($fp, print_r($_SESSION['POST'], true)); fclose($fp); ?> but I see my Log will Log 3 times like this no die Array ( [A] => 1 ) no die Array ( [A] => 1 ) no die Array ( [A] => 1 ) Edited August 9, 2016 by AlanFan (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 It only appears once for me, so your file is being called three times, unless you forgot to clear the log before trying again. Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 (edited) I try this can got Log <?php session_start(); $_SESSION['POST']=$_POST; $file_name = date('Ymd', time()) . '.txt'; $file = dirname(__FILE__)."/log/". $file_name; $fp = fopen($file, 'a'); fwrite($fp,"\r\n". 'no die'."\r\n"); fwrite($fp, print_r($_SESSION['POST'], true)); fclose($fp); include_once(dirname(__FILE__) . '/../../config/config.inc.php'); include_once(dirname(__FILE__) . '/../../init.php'); include_once(dirname(__FILE__) . '/../../classes/order/OrderHistory.php'); include_once(dirname(__FILE__) . '/../../classes/order/Order.php'); ?> I try this can't <?php session_start(); $_SESSION['POST']=$_POST; include_once(dirname(__FILE__) . '/../../config/config.inc.php'); $file_name = date('Ymd', time()) . '.txt'; $file = dirname(__FILE__)."/log/". $file_name; $fp = fopen($file, 'a'); fwrite($fp,"\r\n". 'no die'."\r\n"); fwrite($fp, print_r($_SESSION['POST'], true)); fclose($fp); include_once(dirname(__FILE__) . '/../../init.php'); include_once(dirname(__FILE__) . '/../../classes/order/OrderHistory.php'); include_once(dirname(__FILE__) . '/../../classes/order/Order.php'); ?> Edited August 9, 2016 by AlanFan (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 Both work for me, though I'm getting an error that hitrustpay.php doesn't exist, since I don't have access to that module. Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 Sorry that is my module .Delete it but have same Error ~ I think Config.inc load me to another page like this is it possiable? https://www.prestashop.com/forums/topic/375109-require-configincphp-doesnt-work-and-load-homepage-instead/ Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 It's possible, but I'm using XAMPP too. You might be using a different version than me though. Do you have an online server you can test it on? Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 It's possible, but I'm using XAMPP too. You might be using a different version than me though. Do you have an online server you can test it on? I was using WampServer Version 3.0.4 32bit Apache 2.4.18 - PHP 5.6.19 - MySQL 5.7.11 Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 Oh, then we're not using the same. I don't have experience with WAMP. I'm hoping it's just a localhost issue and that your problem will disappear when you upload to a server. Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 It only appears once for me, so your file is being called three times, unless you forgot to clear the log before trying again. OK , Thanks your help , I will try on the XAMPP Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 Oh, then we're not using the same. I don't have experience with WAMP. I'm hoping it's just a localhost issue and that your problem will disappear when you upload to a server. I try XAMPP but not this problem. I change the include try to only include some in the Config.inc.php like this <?php session_start(); $result=$_POST; include_once(dirname(__FILE__).' /../../config/defines.inc.php'); include_once(dirname(__FILE__).' /../../config/autoload.php'); include_once(dirname(__FILE__) .' /../../tools/profiling/Controller.php'); include_once(dirname(__FILE__) .' /../../tools/profiling/ObjectModel.php'); include_once(dirname(__FILE__) .' /../../tools/profiling/Db.php'); include_once(dirname(__FILE__) .' /../../tools/profiling/Tools.php'); include_once(dirname(__FILE__) . '/../../classes/order/OrderHistory.php'); include_once(dirname(__FILE__) . '/../../classes/order/Order.php'); $file_name = date('Ymd', time()) . '.txt'; $file = dirname(__FILE__)."/log/". $file_name; $fp = fopen($file, 'a'); fwrite($fp,"\r\n". 'no die'."\r\n"); fwrite($fp, print_r($result, true)); fclose($fp); $order_id = (int)$result['ordernumber']; //$result['ordernumber']='1'; order_id $objOrder = new Order($order_id); $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(2, (int)($objOrder->id)); # Send a mail $history->addWithemail(); ?> and work Log now but still can't changeIdOrderState() phperrorLog [09-Aug-2016 08:13:59 Europe/Berlin] PHP Fatal error: Uncaught exception 'Adapter_Exception' with message 'Service container is not set.' in C:\xampp\htdocs\prestashop\Adapter\Adapter_ServiceLocator.php:49 Stack trace: #0 C:\xampp\htdocs\prestashop\classes\ObjectModel.php(232): Adapter_ServiceLocator::get('Adapter_EntityM...') #1 C:\xampp\htdocs\prestashop\tools\profiling\ObjectModel.php(33): ObjectModelCore->__construct(30, NULL, NULL) #2 C:\xampp\htdocs\prestashop\classes\order\Order.php(283): ObjectModel->__construct(30, NULL) #3 C:\xampp\htdocs\prestashop\modules\hitrustpay\doFictitiousDetonate.php(62): OrderCore->__construct(30) #4 {main} thrown in C:\xampp\htdocs\prestashop\Adapter\Adapter_ServiceLocator.php on line 49 Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 You need bootstrap.php, which creates that container. You could try calling just bootstrap.php like this: include_once(dirname(__FILE__).' /../../config/bootstrap.php'); Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 I include bootstrap.php but got another error now [09-Aug-2016 06:52:01 UTC] PHP Warning: array_key_exists() expects parameter 2 to be array, null given in C:\wamp\www\prestashop\classes\Language.php on line 645 [09-Aug-2016 06:52:01 UTC] PHP Stack trace: [09-Aug-2016 06:52:01 UTC] PHP 1. {main}() C:\wamp\www\prestashop\modules\hitrustpay\doFictitiousDetonate.php:0 [09-Aug-2016 06:52:01 UTC] PHP 2. OrderHistoryCore->changeIdOrderState() C:\wamp\www\prestashop\modules\hitrustpay\doFictitiousDetonate.php:65 [09-Aug-2016 06:52:01 UTC] PHP 3. ObjectModelCore->__construct() C:\wamp\www\prestashop\classes\order\OrderHistory.php:96 [09-Aug-2016 06:52:01 UTC] PHP 4. LanguageCore::getLanguage() C:\wamp\www\prestashop\classes\ObjectModel.php:219 [09-Aug-2016 06:52:01 UTC] PHP 5. array_key_exists() C:\wamp\www\prestashop\classes\Language.php:645 [09-Aug-2016 06:52:01 UTC] PHP Fatal error: Call to a member function getContextShopID() on null in C:\wamp\www\prestashop\classes\Hook.php on line 472 [09-Aug-2016 06:52:01 UTC] PHP Stack trace: [09-Aug-2016 06:52:01 UTC] PHP 1. {main}() C:\wamp\www\prestashop\modules\hitrustpay\doFictitiousDetonate.php:0 [09-Aug-2016 06:52:01 UTC] PHP 2. OrderHistoryCore->changeIdOrderState() C:\wamp\www\prestashop\modules\hitrustpay\doFictitiousDetonate.php:65 [09-Aug-2016 06:52:01 UTC] PHP 3. HookCore::exec() C:\wamp\www\prestashop\classes\order\OrderHistory.php:105 Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 Seems you really do need to load config/config.inc.php. It's line 139 that will fix that problem: Language::loadLanguages(); Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 (edited) Seems you really do need to load config/config.inc.php. It's line 139 that will fix that problem: Language::loadLanguages(); But if I include config.inc.php will not work , sorry is too many question. My code Change like below now , and I find where I will appear error <?php session_start(); $result=$_POST; include_once(dirname(__FILE__).' /../../config/defines.inc.php'); include_once(dirname(__FILE__).' /../../config/autoload.php'); require_once (dirname(__FILE__). '/../../config/bootstrap.php'); include_once(dirname(__FILE__) .' /../../tools/profiling/Controller.php'); include_once(dirname(__FILE__) .' /../../tools/profiling/ObjectModel.php'); include_once(dirname(__FILE__) .' /../../tools/profiling/Db.php'); include_once(dirname(__FILE__) .' /../../tools/profiling/Tools.php'); $context = Context::getContext(); /* Initialize the current Shop */ try { $context->shop = Shop::initialize(); $context->theme = new Theme((int)$context->shop->id_theme); if ((Tools::isEmpty($theme_name = $context->shop->getTheme()) || !Validate::isLoadedObject($context->theme)) && !defined('_PS_ADMIN_DIR_')) { throw new PrestaShopException(Tools::displayError('Current theme unselected. Please check your theme configuration.')); } } catch (PrestaShopException $e) { $e->displayMessage(); } define('_THEME_NAME_', $theme_name); define('__PS_BASE_URI__', $context->shop->getBaseURI()); /* Include all defines related to base uri and theme name */ require_once(dirname(__FILE__).' /../../config/defines_uri.inc.php'); Language::loadLanguages(); require_once(dirname(__FILE__) .' /../../tools/htmlpurifier/HTMLPurifier.standalone.php'); include_once(dirname(__FILE__) . '/../../classes/order/OrderHistory.php'); include_once(dirname(__FILE__) . '/../../classes/order/Order.php'); $file_name = date('Ymd', time()) . '.txt'; $file = dirname(__FILE__)."/log/". $file_name; $fp = fopen($file, 'a'); fwrite($fp,"\r\n". 'no die'."\r\n"); fwrite($fp, print_r($result, true)); fclose($fp); $order_id = (int)$result['ordernumber']; //$result['ordernumber']='1'; order_id $objOrder = new Order($order_id); $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(2, (int)($objOrder->id)); # Send a mail $history->addWithemail(); ?> if I code this in php will die /* Initialize the current Shop */ try { $context->shop = Shop::initialize(); $context->theme = new Theme((int)$context->shop->id_theme); if ((Tools::isEmpty($theme_name = $context->shop->getTheme()) || !Validate::isLoadedObject($context->theme)) && !defined('_PS_ADMIN_DIR_')) { throw new PrestaShopException(Tools::displayError('Current theme unselected. Please check your theme configuration.')); } } catch (PrestaShopException $e) { $e->displayMessage(); } Edited August 9, 2016 by AlanFan (see edit history) Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 Seems you really do need to load config/config.inc.php. It's line 139 that will fix that problem: Language::loadLanguages(); and I add this another error [09-Aug-2016 07:47:56 UTC] PHP Fatal error: Call to a member function getContextShopID() on null in C:\wamp\www\prestashop\classes\Hook.php on line 472 [09-Aug-2016 07:47:56 UTC] PHP Stack trace: [09-Aug-2016 07:47:56 UTC] PHP 1. {main}() C:\wamp\www\prestashop\modules\hitrustpay\doFictitiousDetonate.php:0 [09-Aug-2016 07:47:56 UTC] PHP 2. OrderHistoryCore->changeIdOrderState() C:\wamp\www\prestashop\modules\hitrustpay\doFictitiousDetonate.php:75 [09-Aug-2016 07:47:56 UTC] PHP 3. HookCore::exec() C:\wamp\www\prestashop\classes\order\OrderHistory.php:105 Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 It seems removing config/config.inc.php isn't working. I suggest putting config/config.inc.php back in and then trying to trace the cause of PHP dying. Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 It seems removing config/config.inc.php isn't working. I suggest putting config/config.inc.php back in and then trying to trace the cause of PHP dying. I find die at this $context->shop = Shop::initialize(); Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 There are two exit; lines in that function, but the header calls should redirect the page. Link to comment Share on other sites More sharing options...
AlanFan Posted August 9, 2016 Author Share Posted August 9, 2016 (edited) There are two exit; lines in that function, but the header calls should redirect the page. What should I do ? I just want to get Post[ order_id ] when customer has pay in PaymentServer and I need to Update to ChangeOrderStatus but seem like it lost cookies so need to Shop::initialize(); again?? Edited August 9, 2016 by AlanFan (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted August 9, 2016 Share Posted August 9, 2016 Make sure that _PS_ADMIN_DIR_ is defined and that your browser domain matches the shop URL specified on the Preferences > SEO & URLs (or Advanced Parameters > Multistore if you're using multistore) Link to comment Share on other sites More sharing options...
AlanFan Posted August 10, 2016 Author Share Posted August 10, 2016 Make sure that _PS_ADMIN_DIR_ is defined and that your browser domain matches the shop URL specified on the Preferences > SEO & URLs (or Advanced Parameters > Multistore if you're using multistore) How to check it _PS_ADMIN_DIR_ is defined ? It seems like the extranl IP Post data to page B.php on My Server and it call the Shop initialize (); and reload my B.php to localhost/prestashop/index.php and I think My post url is Myserver's ExtranlIP(xxx.xxx.xxx.xxx:28080)/prestashop/...../B.php but at Shop initialize (); to check my url will turn the page to localhost/prestashop And I just only one store. Link to comment Share on other sites More sharing options...
rocky Posted August 10, 2016 Share Posted August 10, 2016 You can use the following to check whether _PS_ADMIN_DIR_ is defined: echo _PS_ADMIN_DIR_; If the result is _PS_ADMIN_DIR_, then it's not defined and you'll need to define it. Link to comment Share on other sites More sharing options...
AlanFan Posted August 10, 2016 Author Share Posted August 10, 2016 You can use the following to check whether _PS_ADMIN_DIR_ is defined: echo _PS_ADMIN_DIR_; If the result is _PS_ADMIN_DIR_, then it's not defined and you'll need to define it. echo _PS_ADMIN_DIR_; in my B.php then got this [10-Aug-2016 06:33:47 UTC] PHP Notice: Use of undefined constant _PS_ADMIN_DIR_ - assumed '_PS_ADMIN_DIR_' in C:\wamp\www\prestashop\modules\hitrustpay\doFictitiousDetonate.php on line 4 Is it defined in my B.php? Can you give me example ? Thanks you very much. Link to comment Share on other sites More sharing options...
AlanFan Posted August 10, 2016 Author Share Posted August 10, 2016 (edited) by the way my B.php is backoffice to update OrderStatus when user completed payment and it will turn page to Home (/prestashop/index.php) and payment server also will post order_Id and some information to B.php When I use My phone surf my store and order will die in B.php config.inc.php But when I use phone surf to my domain server/POST.php post same data to B.php will work and updateOrderStatus the differences in different servers Post which post it . Edited August 10, 2016 by AlanFan (see edit history) Link to comment Share on other sites More sharing options...
AlanFan Posted August 10, 2016 Author Share Posted August 10, 2016 You can use the following to check whether _PS_ADMIN_DIR_ is defined: echo _PS_ADMIN_DIR_; If the result is _PS_ADMIN_DIR_, then it's not defined and you'll need to define it. Thanks you so much , I resolved it !!!! add _PS_ADMIN_DIR_ defined ~~! Link to comment Share on other sites More sharing options...
rocky Posted August 10, 2016 Share Posted August 10, 2016 Great. I'm happy it finally works. Link to comment Share on other sites More sharing options...
AlanFan Posted August 10, 2016 Author Share Posted August 10, 2016 Great. I'm happy it finally works. Thanks your help in this few day. Link to comment Share on other sites More sharing options...
rocky Posted August 10, 2016 Share Posted August 10, 2016 You're welcome. 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