opencart php program stopped after dispatch() - php

My opencart front-end works well, while back-end /admin returns me blank page.
I debugged my /admin/index.php and find after
$controller->dispatch($action, new Action('error/not_found'));
the program stopped. So I won't be able to see even the echo.
Here is the code:
Back-end admin/index.php
// Router
if (isset($request->get['route'])) {
$action = new Action($request->get['route']);
} else {
$action = new Action('common/home');
}
// Dispatch
var_dump($action);
$controller->dispatch($action, new Action('error/not_found'));
echo "second+++++++++++++++++++++++++++++++++";
var_dump($response);
// Output
$response->output();
By the way the frond end works well, as it returned me echo and $response value after dispatch:
if (isset($request->get['route'])) {
$action = new Action($request->get['route']);
} else {
$action = new Action($config->get('config_default_controller'));
}
// Dispatch
var_dump($action);
$controller->dispatch($action, new Action($config->get('config_default_controller_error')));
echo "second++++++++++++++++++++++++++";
var_dump($response);
I have checked the $action and $controller they are all with good values and paths.
Do anyone know what happened here with dispatch ? or give me any information about dispatch and why the program stop. Thank you in advance.

after few hours i found solution.
In my case it was wrong config. I had same issue and after checking what is wrong i figure out that my paths in config.php file in admin folder was with wrong values.
Opencart have two cfg files.
Next thing what i changed was config_url in database. Hope it will help you.

Related

Phalcon: How to use Phalcon\Debug, but control the output for development/production environment?

I have a small application on the specified framework. I want to control what the user sees if my application fails. This should not be a standard web server response, which it is differently displayed by different browsers. In this regard, I want to use Falcon\Debug. But, as far as I understand, this component of the framework will always show something like this:
However, I would like to show this information only if debugging is enabled in my application (using an environment variable, for example). In other cases I would like to show just a page describing the error.
Question: how to implement this?
This is my implementation in the index.php file:
try {
$root = str_replace('\\', '/', dirname(dirname(__FILE__))) . '/';
require_once $root . 'apps/Bootstrap.php';
$bootstrap = new Bootstrap();
$bootstrap->run();
} catch (\Exception $e) {
if (DEV_MODE === true) {
$debug = new \Phalcon\Debug();
die($debug->listen()->onUncaughtException($e));
} else {
header('HTTP/1.1 500 Internal Server Error');
// Your fancy error page for users here!
die();
}
}
The idea is to have a variable somewhere in your config files which you can easily switch between true/false.
Update!
You can add this too:
if (DEV_MODE === true) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
} else {
error_reporting(0);
}
Complementing the proposal solution by Nikolay Mihaylov, maybe you want to redirect to a specific view and so not show blank page or default error 500 in browser, thereforce, only need add the NameSpace at the beginning
use Phalcon\Http\Response
and redirect in catch block, here a little example:
try {
// some code
} catch (\Exception $e) {
// ... some code
$response = new Response();
// Redirect...
$response->redirect('controller/view'); // for example, you could create a view to show error 500
// Send response to the client
$response->send();
}

Opencart redirect defined routes

I'm have couple of not used routes and searching for solutions to redirect this routes.
For example I have ['common/cart','affiliate/edit' ]
array of routes, and where I can add check to check If route is in this array redirect to 404 ? I think that can be done in /controller/common/seo_url.php ?
There are many places where you can add your redirection conditions, the most important thing is avoiding changing the code of core libraries, so I think that the best place would be in index.php
Open the file <OC_ROOT>/index.php
Search for this code fragment:
if (isset($request->get['route'])) {
$action = new Action($request->get['route']);
} else {
$action = new Action('common/home');
}
In the isset part, you can check if the variable $request->get['route'] matches any of your obsolete routes and redirect on that basis, for example:
if (isset($request->get['route'])) {
$ignored_routes = array('common/cart', 'affiliate/edit');
if(in_array($request->get['route'], $ignored_routes))
$action = new Action("error/not_found");
else
$action = new Action($request->get['route']);
} else {
$action = new Action('common/home');
}
P.S: Your assumption is wrong, you can't do it in the file /controller/common/seo_url.php, what you want is <OC_ROOT>/system/engine/action.php ;)

Testing user identification before any request

I wondering how to perform an access control in a entire module. Let me explain : If I have got a module (/authentication/) which is only developed to create a session. And a another module (/Main/) which contains the main application.
What I want to do is to check in any request on the main module if a session was correctly created by a user.
During my research on the internet, I saw a method to do it. I'm not sure, so tell me if my solution is good : I will implemente an event in my bootstrap function (on module.php) which will check if the session is correctly created. If it is not I will redirect to the module authentication.
public function onBootstrap($e){
$eventManager = $e->getApplication()->getEventManager();
$auth = new AuthenticationService();
if (!$auth->hasIdentity()) {
$response = $e->getResponse();
$response->getHeaders()->addHeaderLine('Location', 'authentification');
$response->setStatusCode(302);
}
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
What do you think about this solution ?
Unfortunately this solution is not good.
I don't know why, but it seem that this code is executed even in the module authentication.
So at the first call when you are trying to go in the url : /main, you will be redirect to the module /authentication and again the code will be re-executed and the module will redirect you to /authentication and again and again and again...
So I think the solution is to check if the requested url is different from this one /authentication.
How to do this ?
Hope my question is clear and easily understandable.
Thank you =D
public function onBootstrap(MvcEvent $e) {
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach(MvcEvent::EVENT_DISPATCH, function($e) {
$controller = $e->getTarget();
$auth = new AuthenticationService();
$is_login = $auth->hasIdentity();
//check if action is login
$params = $e->getApplication()->getMvcEvent()->getRouteMatch()->getParams();
if ($params['action'] == 'login') {
if ($is_login) {
return $controller->redirect()->toRoute('adminindex');
}
} else {
if (!$is_login) {
return $controller->redirect()->toRoute('adminauthlogin');
}
}
});
}
a little bit better solution ;)

PHP MySQL Yii - database reading not writing

I have a working Yii app on my local lamp stack. Now when I put the app on a lamp server the app reads the db and runs, but the app isn't successfully writing to the db. I'm getting no errors logs. Any thoughts?
Here's how I'm updating the db:
public function actionIndex()
{
if ($_GET["yep"] == "") {
pd_error("You are not logged in!");
}
list($uid, $domain) = preg_split("/#/",$_GET["yep"],2);
$model=$this->loadModel($uid);
$this->redirect($model->URL."?".$model->Unique_ID);
}
public function loadModel($uid)
{
$model=People::model()->findByPk($uid);
$model->Login_Count++;
$model->Last_Logged=date('Y-m-d H:i:s');
if ($model->validate()) {
$model->save();
} else {
$this->render('notice');
}
return $model;
}
The weird thing is, even when the db doesn't update the Login_Count and Last_Logged the user still gets redirected to their url, so the sql must be valid because the notice page never loads. Any thoughts?
Update + Solution
The problem ended up being that the mysql server had autocommit set to false. To override this at the app level add the following line to the config/main.php db array:
'db'=>array(
...
'initSQLs'=>array('SET AUTOCOMMIT=1',),
...
);
Yii: using active record with autocommit off on mysql server
The rendering of notice page doesn't stop your redirect. It might be rendered, but you won't be able to see it because of redirect. Try to refactor your code.
You're validating your model twice and the validation probably might be skipped since there's no data coming from App user.
You don't check if People model actually found.
There is CWebUser::afterLogin method which you can override to do this kind of stuff (update login count and last login date)
Maybe this way (quick fix) will work:
function actionIndex()
{
if ($_GET["yep"] == "") {
pd_error("You are not logged in!");
}
list($uid, $domain) = preg_split("/#/",$_GET["yep"],2);
if (null === ($model=People::model()->findByPk($uid))
throw new CHttpException(404);
$model->Login_Count++;
$model->Last_Logged=date('Y-m-d H:i:s');
if ($model->save()) {
$this->redirect($model->URL."?".$model->Unique_ID);
} else {
// echo CHtml::errorSummary($model)
$this->render('notice');
}
}

Returning Boolean Value PHP MongoDB

I am trying to implement error proofing to a log in script. But, I cannot get it to work? I have no idea what is going on, or why it doesn't work like I expect it to. I have tried everything, please advise.
This is the method I am calling:
public function i_exist($this_username)
{
//$host_array = null;
//$host_array = $this->collection->findOne(array("Username" => $this_username));
//if ($host_array['Username'] = $this_username)
//{
return true;
//}
//return false;
}
This is how I am calling it:
if (!empty($_POST['Username']))
{
$host = new Host();
$event = new Event();
if ($host->i_exist($_POST['Username']))
{
header("Location: http://www.drink-social.com/error.php?login=duplicate");
}
It is supposed to check the database and see if that username is already in use. But it never directs to the error page? I have even tried commenting everything out and returning true, and returning 1. Nothing?
Any advice?
When you call header(); you will also need to call exit(); otherwise the script continues running.

Categories