tttaaabbb tttaaabbb - 1 year ago 153
PHP Question

Redirect in OpenCart

Hi i have custom controller in admin page, and i want to redirect after some function is done. Here is my code:

public function save(){
//some operations
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".htmlentities ($this->url->link('sale/order', 'token=' . $this->session->data['token'] . '', 'SSL')));

as the result i see this in browser:


Instead of:


How can i fix it?

Answer Source

OpenCart has a built in redirect function as part of the response library.

$this->response->redirect('your url goes here', 'http status code goes here');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download