{"id":93379,"date":"2017-08-23T14:51:33","date_gmt":"2017-08-23T14:51:33","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=93379"},"modified":"2021-07-16T11:50:15","modified_gmt":"2021-07-16T11:50:15","slug":"session-management-opencart-version-3-x","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/","title":{"rendered":"Session Management in Opencart Version 3.x"},"content":{"rendered":"\n<p>With the launch of Opencart Version 3, <strong>Opencart has discontinued the use of native session<\/strong>. Opencart has introduced the&nbsp;&#8220;maintaining of the session using database&#8221; in the version 2.2.0.0 and &#8220;maintaining using the file&#8221; in the version 2.3.0.0 but still, it continued to use the native PHP session ($_SESSION). In version 3, Opencart is&nbsp;using file by default to maintain the session.<\/p>\n\n\n\n<p>If you want to use the database for maintaining the session then you have to modify &#8216;default.php&#8217;&nbsp;file residing at &#8216;system\/config\/&#8217;. You have to modify &#8216;session_engine&#8217; index.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted brush:php\">\/\/ Session\n$_['session_engine']       = 'file'; \/\/ db or file can be placed<\/pre>\n\n\n\n<p>You can take a look into the process of reading and writing of session in both db and file. For accessing the files, you can follow the path &#8216;system\/library\/session\/&#8217;.<\/p>\n\n\n\n<p><strong>File Session:<\/strong><\/p>\n\n\n\n<p><strong>Read:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted brush:php\">public function read($session_id) {\n\t$file = $this-&gt;directory . '\/sess_' . basename($session_id);\n\n\tif (is_file($file)) {\n\t\t$handle = fopen($file, 'r');\n\n\t\tflock($handle, LOCK_SH);\n\n\t\t$data = fread($handle, filesize($file));\n\n\t\tflock($handle, LOCK_UN);\n\n\t\tfclose($handle);\n\n\t\treturn unserialize($data);\n\t} else {\n\t\treturn array();\n\t}\n}<\/pre>\n\n\n\n<p><strong>Write:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted brush:php\">public function write($session_id, $data) {\n\t$file = $this-&gt;directory . '\/sess_' . basename($session_id);\n\n\t$handle = fopen($file, 'w');\n\n\tflock($handle, LOCK_EX);\n\n\tfwrite($handle, serialize($data));\n\n\tfflush($handle);\n\n\tflock($handle, LOCK_UN);\n\n\tfclose($handle);\n\n\treturn true;\n}<\/pre>\n\n\n\n<p><strong>DB Session:<\/strong><\/p>\n\n\n\n<p><strong>Read:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted brush:php\">public function read($session_id) {\n\t$query = $this-&gt;db-&gt;query(\"SELECT `data` FROM `\" . DB_PREFIX . \"session` WHERE session_id = '\" . $this-&gt;db-&gt;escape($session_id) . \"' AND expire &gt; \" . (int)time());\n\t\n\tif ($query-&gt;num_rows) {\n\t\treturn $query-&gt;row['data'];\n\t} else {\n\t\treturn false;\n\t}\n}<\/pre>\n\n\n\n<p><strong>Write:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted brush:php\">public function write($session_id, $data) {\n\t$this-&gt;db-&gt;query(\"REPLACE INTO SET `data` = '\" . $this-&gt;db-&gt;escape($data) . \"', expire = '\" . $this-&gt;db-&gt;escape(date('Y-m-d H:i:s', time() + $this-&gt;expire)) . \"' FROM `\" . DB_PREFIX . \"session` WHERE session_id = '\" . $this-&gt;db-&gt;escape($session_id) . \"' AND expire &gt; \" . (int)time());\n\t\n\treturn true;\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>With the launch of Opencart Version 3, Opencart has discontinued the use of native session. Opencart has introduced the&nbsp;&#8220;maintaining of the session using database&#8221; in the version 2.2.0.0 and &#8220;maintaining using the file&#8221; in the version 2.3.0.0 but still, it continued to use the native PHP session ($_SESSION). In version 3, Opencart is&nbsp;using file by <a href=\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":70,"featured_media":41008,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[305],"tags":[2071,5357,5358,1869],"class_list":["post-93379","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opencart","tag-opencart","tag-opencart-session","tag-opencart-version-3","tag-session"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Session Management in Opencart Version 3.x - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Session Management in Opencart Version 3.x - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"With the launch of Opencart Version 3, Opencart has discontinued the use of native session. Opencart has introduced the&nbsp;&#8220;maintaining of the session using database&#8221; in the version 2.2.0.0 and &#8220;maintaining using the file&#8221; in the version 2.3.0.0 but still, it continued to use the native PHP session ($_SESSION). In version 3, Opencart is&nbsp;using file by [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-08-23T14:51:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-16T11:50:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Opencart-Code-Snippet.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vikhyat Sharma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vikhyat Sharma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/\"},\"author\":{\"name\":\"Vikhyat Sharma\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/af7160d2546c64a1856ab1b5ce77d9b0\"},\"headline\":\"Session Management in Opencart Version 3.x\",\"datePublished\":\"2017-08-23T14:51:33+00:00\",\"dateModified\":\"2021-07-16T11:50:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/\"},\"wordCount\":138,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Opencart-Code-Snippet.png\",\"keywords\":[\"opencart\",\"opencart session\",\"opencart version 3\",\"session\"],\"articleSection\":[\"opencart\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/\",\"url\":\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/\",\"name\":\"Session Management in Opencart Version 3.x - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Opencart-Code-Snippet.png\",\"datePublished\":\"2017-08-23T14:51:33+00:00\",\"dateModified\":\"2021-07-16T11:50:15+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Opencart-Code-Snippet.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Opencart-Code-Snippet.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Session Management in Opencart Version 3.x\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/af7160d2546c64a1856ab1b5ce77d9b0\",\"name\":\"Vikhyat Sharma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7c9c700cc2d7120c9faf1ab3392b4e533808ba197f58c0441d6caecc68179e12?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7c9c700cc2d7120c9faf1ab3392b4e533808ba197f58c0441d6caecc68179e12?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Vikhyat Sharma\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/vikhyat-sharma83\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Session Management in Opencart Version 3.x - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/","og_locale":"en_US","og_type":"article","og_title":"Session Management in Opencart Version 3.x - Webkul Blog","og_description":"With the launch of Opencart Version 3, Opencart has discontinued the use of native session. Opencart has introduced the&nbsp;&#8220;maintaining of the session using database&#8221; in the version 2.2.0.0 and &#8220;maintaining using the file&#8221; in the version 2.3.0.0 but still, it continued to use the native PHP session ($_SESSION). In version 3, Opencart is&nbsp;using file by [...]","og_url":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2017-08-23T14:51:33+00:00","article_modified_time":"2021-07-16T11:50:15+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Opencart-Code-Snippet.png","type":"image\/png"}],"author":"Vikhyat Sharma","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Vikhyat Sharma","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/"},"author":{"name":"Vikhyat Sharma","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/af7160d2546c64a1856ab1b5ce77d9b0"},"headline":"Session Management in Opencart Version 3.x","datePublished":"2017-08-23T14:51:33+00:00","dateModified":"2021-07-16T11:50:15+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/"},"wordCount":138,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Opencart-Code-Snippet.png","keywords":["opencart","opencart session","opencart version 3","session"],"articleSection":["opencart"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/","url":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/","name":"Session Management in Opencart Version 3.x - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Opencart-Code-Snippet.png","datePublished":"2017-08-23T14:51:33+00:00","dateModified":"2021-07-16T11:50:15+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Opencart-Code-Snippet.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Opencart-Code-Snippet.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/session-management-opencart-version-3-x\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Session Management in Opencart Version 3.x"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/af7160d2546c64a1856ab1b5ce77d9b0","name":"Vikhyat Sharma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7c9c700cc2d7120c9faf1ab3392b4e533808ba197f58c0441d6caecc68179e12?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7c9c700cc2d7120c9faf1ab3392b4e533808ba197f58c0441d6caecc68179e12?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Vikhyat Sharma"},"url":"https:\/\/webkul.com\/blog\/author\/vikhyat-sharma83\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/93379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/70"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=93379"}],"version-history":[{"count":2,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/93379\/revisions"}],"predecessor-version":[{"id":296486,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/93379\/revisions\/296486"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/41008"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=93379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=93379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=93379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}