{"id":1674,"date":"2022-08-30T15:18:30","date_gmt":"2022-08-30T15:18:30","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/an-idea-about-login-script-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:18:30","modified_gmt":"2022-08-30T15:18:30","slug":"an-idea-about-login-script-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/an-idea-about-login-script-collection-of-common-programming-errors\/","title":{"rendered":"An idea about login script-Collection of common programming errors"},"content":{"rendered":"<p>At the moment I think about login script. Idea &#8211; when you submit login and password, they checks into model and if login and password is correct, script shows a message about completed login process. But if I put in view <code>echo $message;<\/code> and I am at login page, kohana shows error &#8211; Undefined variable $message. But when I am at page, where the variable defined, all working. How to realize this idea.<\/p>\n<p>EDIT!<\/p>\n<pre><code>class Controller_About extends Controller_Template {\n\npublic function action_index() {\n    session_start();\n    if (isset($_SESSION['lietotajvards'])) {\n\n        if (!empty($_POST['virsraksts']) and !empty($_POST['saturs'])) {\n\n            $name = Model::factory('index')-&gt;insert_names($_POST['virsraksts'], $_POST['saturs']);\n            $result = $name;\n            $this-&gt;template-&gt;site_name = Kohana::$config-&gt;load('common')-&gt;get('site_name');\n            $this-&gt;template-&gt;site_description = Kohana::$config-&gt;load('common')-&gt;get('site_description');\n            $this-&gt;template-&gt;page_title = 'About';\n            $this-&gt;template-&gt;content = View::factory('about\/about')-&gt;set('result', $result);\n            $this-&gt;template-&gt;styles[] = 'index\/index';\n        } else {\n            $this-&gt;template-&gt;site_name = Kohana::$config-&gt;load('common')-&gt;get('site_name');\n            $this-&gt;template-&gt;site_description = Kohana::$config-&gt;load('common')-&gt;get('site_description');\n            $this-&gt;template-&gt;page_title = 'About';\n            $this-&gt;template-&gt;content = View::factory('about\/about');\n            $this-&gt;template-&gt;styles[] = 'index\/index';\n        }\n    } else {\n        if (!empty($_POST['lietotajvards']) and !empty($_POST['parole'])) {\n            $user_model = Model::factory('index')-&gt;valide($_POST['lietotajvards'], md5($_POST['parole']));\n            foreach ($user_model as $d) {\n                if ($_POST['lietotajvards'] == $d['lietotajvards'] and md5($_POST['parole']) == $d['parole']) {\n                    $_SESSION['lietotajvards'] = $_POST['lietotajvards'];\n                    $this-&gt;template-&gt;content = View::factory('login\/index')-&gt;set('message', 'Ielogosanas veiksmiga!');\n                    echo '';\n                }\n            }\n        }\n        $this-&gt;template-&gt;site_name = Kohana::$config-&gt;load('common')-&gt;get('site_name');\n        $this-&gt;template-&gt;site_description = Kohana::$config-&gt;load('common')-&gt;get('site_description');\n        $this-&gt;template-&gt;page_title = 'About';\n        $this-&gt;template-&gt;content = View::factory('login\/index');\n        $this-&gt;template-&gt;styles[] = 'index\/index';\n    }\n}}\n<\/code><\/pre>\n<p>I have problem only with variable $message.<\/p>\n<pre><code>\n\n    \n    \n    \n\n<\/code><\/pre>\n<ol>\n<li>\n<p>The problem is you&#8217;re setting the template content at the very end, which is overriding what you&#8217;ve previously set it to. Try changing<\/p>\n<pre><code>$this-&gt;template-&gt;content = View::factory('login\/index')-&gt;set('message', 'Ielogosanas veiksmiga!');\n<\/code><\/pre>\n<p>to<\/p>\n<pre><code>$message = 'Ielogosanas veiksmiga!';\n<\/code><\/pre>\n<p>and then at the end change the view loading to<\/p>\n<pre><code>$this-&gt;template-&gt;content = View::factory('login\/index')-&gt;bind('message',$message);\n<\/code><\/pre>\n<p>Using the bind method on the view will pass a null value to the view if the variable has not been set inside your controller.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-27 12:26:55. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>At the moment I think about login script. Idea &#8211; when you submit login and password, they checks into model and if login and password is correct, script shows a message about completed login process. But if I put in view echo $message; and I am at login page, kohana shows error &#8211; Undefined variable [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1674","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1674","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1674"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1674\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}