I am modifying Opencart which contains several modules represented by PHP pages. However my question applies to any case that involves the following. So no need to make this an opencart specific question.
I wish change the way one module/PHP page redirects after it has done it's work.
What I have done is modified the module in question to process a session variable to modify the URL to be redirected to.
Custom page
if ( !$this->customer->isLogged() ) {
$this->session->data['redirect'] = $this->url->link('account/blah');
$this->redirect($this->url->link('account/register', '', 'SSL'));
}
Page where redirection has been modified
if (isset($this->session->data['redirect'])) {
$this->redirect($this->session->data['redirect']);
}
It works but I do not feel it is secure. What could be done to improve it ?
P.S: Here's how redirection is actually handled in opencart.
protected function redirect($url, $status = 302) {
header('Status: ' . $status);
header('Location: ' . str_replace(array('&', "\n", "\r"), array('&', '', ''), $url));
exit();
}