title: My custom Opencart module logs me out of admin when trying to save
body: <p>I have built an OpenCart module to add "articles" to the site. I have done this by cloning the "information" module and then adapting it to my needs. </p>
  
  <p>I have made a lot of progress - pretty much finished what I set out to do - and <strong>everything works fine on my local dev server.</strong> Problem is I've pushed it up to the live server and when I enter the article details and press save (in the admin area) it immediately logs me out, and nothing is saved at all.</p>
  
  <p>My feeling is that it has something to do with the token that gets added when I log in because when I save and I get logged out that token number (appended to the url) is different.</p>
  
  <p>I don't know php all that well (have a background in C# and .NET) but generally understand what's going on. I hope someone can help out.</p>
  
  <p>The Controller file for article: (let me know if any other files/info is needed)</p>
  
  <pre><code>class ControllerCatalogArticle extends Controller { 
      private $error = array();
  
      public function index() {
          $this-&gt;load-&gt;language('catalog/article');
  
          $this-&gt;document-&gt;setTitle($this-&gt;language-&gt;get('heading_title'));
  
          $this-&gt;load-&gt;model('catalog/article');
  
          $this-&gt;getList();
      }
  
      public function insert() {
          $this-&gt;load-&gt;language('catalog/article');
  
          $this-&gt;document-&gt;setTitle($this-&gt;language-&gt;get('heading_title'));
  
          $this-&gt;load-&gt;model('catalog/article');
  
          if (($this-&gt;request-&gt;server['REQUEST_METHOD'] == 'POST') &amp;&amp; $this-&gt;validateForm()) {
              $this-&gt;model_catalog_article-&gt;addArticle($this-&gt;request-&gt;post);
  
              $this-&gt;session-&gt;data['success'] = $this-&gt;language-&gt;get('text_success');
  
              $url = '';
  
              if (isset($this-&gt;request-&gt;get['sort'])) {
                  $url .= '&amp;sort=' . $this-&gt;request-&gt;get['sort'];
              }
  
              if (isset($this-&gt;request-&gt;get['order'])) {
                  $url .= '&amp;order=' . $this-&gt;request-&gt;get['order'];
              }
  
              if (isset($this-&gt;request-&gt;get['page'])) {
                  $url .= '&amp;page=' . $this-&gt;request-&gt;get['page'];
              }
  
              $this-&gt;redirect($this-&gt;url-&gt;link('catalog/article', 'token=' . $this-&gt;session-&gt;data['token'] . $url, 'SSL'));
          }
  
          $this-&gt;getForm();
      }
  
      public function update() {
          $this-&gt;load-&gt;language('catalog/article');
  
          $this-&gt;document-&gt;setTitle($this-&gt;language-&gt;get('heading_title'));
  
          $this-&gt;load-&gt;model('catalog/article');
  
          if (($this-&gt;request-&gt;server['REQUEST_METHOD'] == 'POST') &amp;&amp; $this-&gt;validateForm()) {
              $this-&gt;model_catalog_article-&gt;editArticle($this-&gt;request-&gt;get['article_id'], $this-&gt;request-&gt;post);
  
              $this-&gt;session-&gt;data['success'] = $this-&gt;language-&gt;get('text_success');
  
              $url = '';
  
              if (isset($this-&gt;request-&gt;get['sort'])) {
                  $url .= '&amp;sort=' . $this-&gt;request-&gt;get['sort'];
              }
  
              if (isset($this-&gt;request-&gt;get['order'])) {
                  $url .= '&amp;order=' . $this-&gt;request-&gt;get['order'];
              }
  
              if (isset($this-&gt;request-&gt;get['page'])) {
                  $url .= '&amp;page=' . $this-&gt;request-&gt;get['page'];
              }
  
              $this-&gt;redirect($this-&gt;url-&gt;link('catalog/article', 'token=' . $this-&gt;session-&gt;data['token'] . $url, 'SSL'));
          }
  
          $this-&gt;getForm();
      }
  
      public function delete() {
          $this-&gt;load-&gt;language('catalog/article');
  
          $this-&gt;document-&gt;setTitle($this-&gt;language-&gt;get('heading_title'));
  
          $this-&gt;load-&gt;model('catalog/article');
  
          if (isset($this-&gt;request-&gt;post['selected']) &amp;&amp; $this-&gt;validateDelete()) {
              foreach ($this-&gt;request-&gt;post['selected'] as $article_id) {
                  $this-&gt;model_catalog_article-&gt;deleteArticle($article_id);
              }
  
              $this-&gt;session-&gt;data['success'] = $this-&gt;language-&gt;get('text_success');
  
              $url = '';
  
              if (isset($this-&gt;request-&gt;get['sort'])) {
                  $url .= '&amp;sort=' . $this-&gt;request-&gt;get['sort'];
              }
  
              if (isset($this-&gt;request-&gt;get['order'])) {
                  $url .= '&amp;order=' . $this-&gt;request-&gt;get['order'];
              }
  
              if (isset($this-&gt;request-&gt;get['page'])) {
                  $url .= '&amp;page=' . $this-&gt;request-&gt;get['page'];
              }
  
              $this-&gt;redirect($this-&gt;url-&gt;link('catalog/article', 'token=' . $this-&gt;session-&gt;data['token'] . $url, 'SSL'));
          }
  
          $this-&gt;getList();
      }
  
      private function getList() {
          if (isset($this-&gt;request-&gt;get['sort'])) {
              $sort = $this-&gt;request-&gt;get['sort'];
          } else {
              $sort = 'id.title';
          }
  
          if (isset($this-&gt;request-&gt;get['order'])) {
              $order = $this-&gt;request-&gt;get['order'];
          } else {
              $order = 'ASC';
          }
  
          if (isset($this-&gt;request-&gt;get['page'])) {
              $page = $this-&gt;request-&gt;get['page'];
          } else {
              $page = 1;
          }
  
          $url = '';
  
          if (isset($this-&gt;request-&gt;get['sort'])) {
              $url .= '&amp;sort=' . $this-&gt;request-&gt;get['sort'];
          }
  
          if (isset($this-&gt;request-&gt;get['order'])) {
              $url .= '&amp;order=' . $this-&gt;request-&gt;get['order'];
          }
  
          if (isset($this-&gt;request-&gt;get['page'])) {
              $url .= '&amp;page=' . $this-&gt;request-&gt;get['page'];
          }
  
          $this-&gt;data['breadcrumbs'] = array();
  
          $this-&gt;data['breadcrumbs'][] = array(
              'text'      =&gt; $this-&gt;language-&gt;get('text_home'),
              'href'      =&gt; $this-&gt;url-&gt;link('common/home', 'token=' . $this-&gt;session-&gt;data['token'], 'SSL'),
              'separator' =&gt; false
          );
  
          $this-&gt;data['breadcrumbs'][] = array(
              'text'      =&gt; $this-&gt;language-&gt;get('heading_title'),
              'href'      =&gt; $this-&gt;url-&gt;link('catalog/article', 'token=' . $this-&gt;session-&gt;data['token'] . $url, 'SSL'),
              'separator' =&gt; ' :: '
          );
  
          $this-&gt;data['insert'] = $this-&gt;url-&gt;link('catalog/article/insert', 'token=' . $this-&gt;session-&gt;data['token'] . $url, 'SSL');
          $this-&gt;data['delete'] = $this-&gt;url-&gt;link('catalog/article/delete', 'token=' . $this-&gt;session-&gt;data['token'] . $url, 'SSL'); 
  
          $this-&gt;data['articles'] = array();
  
          $data = array(
              'sort'  =&gt; $sort,
              'order' =&gt; $order,
              'start' =&gt; ($page - 1) * $this-&gt;config-&gt;get('config_admin_limit'),
              'limit' =&gt; $this-&gt;config-&gt;get('config_admin_limit')
          );
  
  
          $article_total = $this-&gt;model_catalog_article-&gt;getTotalArticles();
  
          $results = $this-&gt;model_catalog_article-&gt;getArticles($data);
  
          $this-&gt;load-&gt;model('catalog/article_category');
          foreach ($results as $result) {
              $action = array();
  
              $action[] = array(
                  'text' =&gt; $this-&gt;language-&gt;get('text_edit'),
                  'href' =&gt; $this-&gt;url-&gt;link('catalog/article/update', 'token=' . $this-&gt;session-&gt;data['token'] . '&amp;article_id=' . $result['article_id'] . $url, 'SSL')
              );
  
              $this-&gt;data['articles'][] = array(
                  'article_id' =&gt; $result['article_id'],
                  'category_id' =&gt; $result['category_id'],
                  'title'          =&gt; $result['title'],
                  'sort_order'     =&gt; $result['sort_order'],
                  'selected'       =&gt; isset($this-&gt;request-&gt;post['selected']) &amp;&amp; in_array($result['article_id'], $this-&gt;request-&gt;post['selected']),
                  'action'         =&gt; $action,
                  'article_category' =&gt;   $this-&gt;model_catalog_article_category-&gt;getArticleCategoryTitle($result['category_id'])
              );
  
          }   
  
          $this-&gt;data['heading_title'] = $this-&gt;language-&gt;get('heading_title');
  
          $this-&gt;data['text_no_results'] = $this-&gt;language-&gt;get('text_no_results');
  
          $this-&gt;data['column_title'] = $this-&gt;language-&gt;get('column_title');
          $this-&gt;data['column_article_category'] = $this-&gt;language-&gt;get('column_article_category');       
          $this-&gt;data['column_sort_order'] = $this-&gt;language-&gt;get('column_sort_order');
          $this-&gt;data['column_action'] = $this-&gt;language-&gt;get('column_action');       
  
          $this-&gt;data['button_insert'] = $this-&gt;language-&gt;get('button_insert');
          $this-&gt;data['button_delete'] = $this-&gt;language-&gt;get('button_delete');
  
          if (isset($this-&gt;error['warning'])) {
              $this-&gt;data['error_warning'] = $this-&gt;error['warning'];
          } else {
              $this-&gt;data['error_warning'] = '';
          }
  
          if (isset($this-&gt;session-&gt;data['success'])) {
              $this-&gt;data['success'] = $this-&gt;session-&gt;data['success'];
  
              unset($this-&gt;session-&gt;data['success']);
          } else {
              $this-&gt;data['success'] = '';
          }
  
          $url = '';
  
          if ($order == 'ASC') {
              $url .= '&amp;order=DESC';
          } else {
              $url .= '&amp;order=ASC';
          }
  
          if (isset($this-&gt;request-&gt;get['page'])) {
              $url .= '&amp;page=' . $this-&gt;request-&gt;get['page'];
          }
  
          $this-&gt;data['sort_title'] = $this-&gt;url-&gt;link('catalog/article', 'token=' . $this-&gt;session-&gt;data['token'] . '&amp;sort=id.title' . $url, 'SSL');
          $this-&gt;data['sort_sort_order'] = $this-&gt;url-&gt;link('catalog/article', 'token=' . $this-&gt;session-&gt;data['token'] . '&amp;sort=i.sort_order' . $url, 'SSL');
  
          $url = '';
  
          if (isset($this-&gt;request-&gt;get['sort'])) {
              $url .= '&amp;sort=' . $this-&gt;request-&gt;get['sort'];
          }
  
          if (isset($this-&gt;request-&gt;get['order'])) {
              $url .= '&amp;order=' . $this-&gt;request-&gt;get['order'];
          }
  
          $pagination = new Pagination();
          $pagination-&gt;total = $article_total;
          $pagination-&gt;page = $page;
          $pagination-&gt;limit = $this-&gt;config-&gt;get('config_admin_limit');
          $pagination-&gt;text = $this-&gt;language-&gt;get('text_pagination');
          $pagination-&gt;url = $this-&gt;url-&gt;link('catalog/article', 'token=' . $this-&gt;session-&gt;data['token'] . $url . '&amp;page={page}', 'SSL');
  
          $this-&gt;data['pagination'] = $pagination-&gt;render();
  
          $this-&gt;data['sort'] = $sort;
          $this-&gt;data['order'] = $order;
  
          $this-&gt;template = 'catalog/article_list.tpl';
          $this-&gt;children = array(
              'common/header',
              'common/footer'
          );
  
          $this-&gt;response-&gt;setOutput($this-&gt;render());
      }
  
      private function getForm() {
          $this-&gt;data['heading_title'] = $this-&gt;language-&gt;get('heading_title');
  
          $this-&gt;data['text_default'] = $this-&gt;language-&gt;get('text_default');
          $this-&gt;data['text_enabled'] = $this-&gt;language-&gt;get('text_enabled');
          $this-&gt;data['text_disabled'] = $this-&gt;language-&gt;get('text_disabled');
  
          $this-&gt;data['entry_title'] = $this-&gt;language-&gt;get('entry_title');
          $this-&gt;data['entry_description'] = $this-&gt;language-&gt;get('entry_description');
          $this-&gt;data['entry_meta_title'] = $this-&gt;language-&gt;get('entry_meta_title');
          $this-&gt;data['entry_meta_description'] = $this-&gt;language-&gt;get('entry_meta_description');
          $this-&gt;data['entry_meta_keywords'] = $this-&gt;language-&gt;get('entry_meta_keywords');
          $this-&gt;data['entry_abstract'] = $this-&gt;language-&gt;get('entry_abstract');
          $this-&gt;data['entry_article_category'] = $this-&gt;language-&gt;get('entry_article_category');
          $this-&gt;data['entry_store'] = $this-&gt;language-&gt;get('entry_store');
          $this-&gt;data['entry_keyword'] = $this-&gt;language-&gt;get('entry_keyword');
          $this-&gt;data['entry_sort_order'] = $this-&gt;language-&gt;get('entry_sort_order');
          $this-&gt;data['entry_status'] = $this-&gt;language-&gt;get('entry_status');
          $this-&gt;data['entry_layout'] = $this-&gt;language-&gt;get('entry_layout');
  
          $this-&gt;data['button_save'] = $this-&gt;language-&gt;get('button_save');
          $this-&gt;data['button_cancel'] = $this-&gt;language-&gt;get('button_cancel');
  
          $this-&gt;data['tab_general'] = $this-&gt;language-&gt;get('tab_general');
          $this-&gt;data['tab_data'] = $this-&gt;language-&gt;get('tab_data');
          $this-&gt;data['tab_design'] = $this-&gt;language-&gt;get('tab_design');
  
          $this-&gt;data['token'] = $this-&gt;session-&gt;data['token'];
  
          if (isset($this-&gt;error['warning'])) {
              $this-&gt;data['error_warning'] = $this-&gt;error['warning'];
          } else {
              $this-&gt;data['error_warning'] = '';
          }
  
          if (isset($this-&gt;error['title'])) {
              $this-&gt;data['error_title'] = $this-&gt;error['title'];
          } else {
              $this-&gt;data['error_title'] = array();
          }
  
          if (isset($this-&gt;error['description'])) {
              $this-&gt;data['error_description'] = $this-&gt;error['description'];
          } else {
              $this-&gt;data['error_description'] = array();
          }
  
          if (isset($this-&gt;error['category'])) {
              $this-&gt;data['error_category'] = $this-&gt;error['category'];
          } else {
              $this-&gt;data['error_category'] = array();
          }
  
  
  
          $url = '';
  
          if (isset($this-&gt;request-&gt;get['sort'])) {
              $url .= '&amp;sort=' . $this-&gt;request-&gt;get['sort'];
          }
  
          if (isset($this-&gt;request-&gt;get['order'])) {
              $url .= '&amp;order=' . $this-&gt;request-&gt;get['order'];
          }
  
          if (isset($this-&gt;request-&gt;get['page'])) {
              $url .= '&amp;page=' . $this-&gt;request-&gt;get['page'];
          }
  
          $this-&gt;data['breadcrumbs'] = array();
  
          $this-&gt;data['breadcrumbs'][] = array(
              'text'      =&gt; $this-&gt;language-&gt;get('text_home'),
              'href'      =&gt; $this-&gt;url-&gt;link('common/home', 'token=' . $this-&gt;session-&gt;data['token'], 'SSL'),            
              'separator' =&gt; false
          );
  
          $this-&gt;data['breadcrumbs'][] = array(
              'text'      =&gt; $this-&gt;language-&gt;get('heading_title'),
              'href'      =&gt; $this-&gt;url-&gt;link('catalog/article', 'token=' . $this-&gt;session-&gt;data['token'] . $url, 'SSL'),
              'separator' =&gt; ' :: '
          );
  
          if (!isset($this-&gt;request-&gt;get['article_id'])) {
              $this-&gt;data['action'] = $this-&gt;url-&gt;link('catalog/article/insert', 'token=' . $this-&gt;session-&gt;data['token'] . $url, 'SSL');
          } else {
              $this-&gt;data['action'] = $this-&gt;url-&gt;link('catalog/article/update', 'token=' . $this-&gt;session-&gt;data['token'] . '&amp;article_id=' . $this-&gt;request-&gt;get['article_id'] . $url, 'SSL');
          }
  
          $this-&gt;data['cancel'] = $this-&gt;url-&gt;link('catalog/article', 'token=' . $this-&gt;session-&gt;data['token'] . $url, 'SSL');
  
          if (isset($this-&gt;request-&gt;get['article_id']) &amp;&amp; ($this-&gt;request-&gt;server['REQUEST_METHOD'] != 'POST')) {
              $article_info = $this-&gt;model_catalog_article-&gt;getArticle($this-&gt;request-&gt;get['article_id']);
          }
  
          $this-&gt;load-&gt;model('localisation/language');        
          $this-&gt;data['languages'] = $this-&gt;model_localisation_language-&gt;getLanguages();
  
          if (isset($this-&gt;request-&gt;post['article_description'])) {
              $this-&gt;data['article_description'] = $this-&gt;request-&gt;post['article_description'];
          } elseif (isset($this-&gt;request-&gt;get['article_id'])) {
              $this-&gt;data['article_description'] = $this-&gt;model_catalog_article-&gt;getArticleDescriptions($this-&gt;request-&gt;get['article_id']);
          } else {
              $this-&gt;data['article_description'] = array();
          }
  
          $this-&gt;load-&gt;model('catalog/article');
  
          $this-&gt;data['article_categories'] = $this-&gt;model_catalog_article-&gt;getArticleCategoriesSort();
  
          if (isset($this-&gt;request-&gt;post['select_categories'])) {
              $this-&gt;data['category_id'] = $this-&gt;request-&gt;post['select_categories'];
  
          } elseif (!empty($article_info)) {
              $this-&gt;data['category_id'] = $article_info['category_id'];
  
          } else {
              $this-&gt;data['category_id'] = 0;
  
          } 
  
  
          if (isset($this-&gt;request-&gt;post['status'])) {
              $this-&gt;data['status'] = $this-&gt;request-&gt;post['status'];
          } elseif (!empty($article_info)) {
              $this-&gt;data['status'] = $article_info['status'];
          } else {
              $this-&gt;data['status'] = 1;
          }
  
          $this-&gt;load-&gt;model('setting/store');
  
          $this-&gt;data['stores'] = $this-&gt;model_setting_store-&gt;getStores();
  
          if (isset($this-&gt;request-&gt;post['article_store'])) {
              $this-&gt;data['article_store'] = $this-&gt;request-&gt;post['article_store'];
          } elseif (isset($this-&gt;request-&gt;get['article_id'])) {
              $this-&gt;data['article_store'] = $this-&gt;model_catalog_article-&gt;getArticleStores($this-&gt;request-&gt;get['article_id']);
          } else {
              $this-&gt;data['article_store'] = array(0);
          }       
  
          if (isset($this-&gt;request-&gt;post['keyword'])) {
              $this-&gt;data['keyword'] = $this-&gt;request-&gt;post['keyword'];
          } elseif (!empty($article_info)) {
              $this-&gt;data['keyword'] = $article_info['keyword'];
          } else {
              $this-&gt;data['keyword'] = '';
          }
  
          if (isset($this-&gt;request-&gt;post['sort_order'])) {
              $this-&gt;data['sort_order'] = $this-&gt;request-&gt;post['sort_order'];
          } elseif (!empty($article_info)) {
              $this-&gt;data['sort_order'] = $article_info['sort_order'];
          } else {
              $this-&gt;data['sort_order'] = '';
          }
  
          if (isset($this-&gt;request-&gt;post['article_layout'])) {
              $this-&gt;data['article_layout'] = $this-&gt;request-&gt;post['article_layout'];
          } elseif (isset($this-&gt;request-&gt;get['article_id'])) {
              $this-&gt;data['article_layout'] = $this-&gt;model_catalog_article-&gt;getArticleLayouts($this-&gt;request-&gt;get['article_id']);
          } else {
              $this-&gt;data['article_layout'] = array();
          }   
  
          $this-&gt;load-&gt;model('design/layout');
  
          $this-&gt;data['layouts'] = $this-&gt;model_design_layout-&gt;getLayouts();
  
          $this-&gt;template = 'catalog/article_form.tpl';
          $this-&gt;children = array(
              'common/header',
              'common/footer'
          );
  
          $this-&gt;response-&gt;setOutput($this-&gt;render());
      }
  
      private function validateForm() {
          if (!$this-&gt;user-&gt;hasPermission('modify', 'catalog/article')) {
              $this-&gt;error['warning'] = $this-&gt;language-&gt;get('error_permission');
          }   
  
          foreach ($this-&gt;request-&gt;post['article_description'] as $language_id =&gt; $value) {           
              if ((utf8_strlen($value['title']) &lt; 3) || (utf8_strlen($value['title']) &gt; 64)) {
                  $this-&gt;error['title'][$language_id] = $this-&gt;language-&gt;get('error_title');
              }       
              if (utf8_strlen($value['description']) &lt; 3) {
                  $this-&gt;error['description'][$language_id] = $this-&gt;language-&gt;get('error_description');
              }   
  
  
          }
  
          if ($this-&gt;error &amp;&amp; !isset($this-&gt;error['warning'])) {
              $this-&gt;error['warning'] = $this-&gt;language-&gt;get('error_warning');
          }
  
          if (!$this-&gt;error) {
              return true;
          } else {
              return false;
          }
      }
  
      private function validateDelete() {
          if (!$this-&gt;user-&gt;hasPermission('modify', 'catalog/article')) {
              $this-&gt;error['warning'] = $this-&gt;language-&gt;get('error_permission');
          }
  
          $this-&gt;load-&gt;model('setting/store');
  
          foreach ($this-&gt;request-&gt;post['selected'] as $article_id) {
              if ($this-&gt;config-&gt;get('config_account_id') == $article_id) {
                  $this-&gt;error['warning'] = $this-&gt;language-&gt;get('error_account');
              }
  
              if ($this-&gt;config-&gt;get('config_checkout_id') == $article_id) {
                  $this-&gt;error['warning'] = $this-&gt;language-&gt;get('error_checkout');
              }
  
              if ($this-&gt;config-&gt;get('config_affiliate_id') == $article_id) {
                  $this-&gt;error['warning'] = $this-&gt;language-&gt;get('error_affiliate');
              }
  
              $store_total = $this-&gt;model_setting_store-&gt;getTotalStoresByArticleId($article_id);
  
              if ($store_total) {
                  $this-&gt;error['warning'] = sprintf($this-&gt;language-&gt;get('error_store'), $store_total);
              }
          }
  
          if (!$this-&gt;error) {
              return true;
          } else {
              return false;
          }
      }
  }
  </code></pre>