{"id":4078,"date":"2019-04-03T18:48:29","date_gmt":"2019-04-03T13:18:29","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=4078"},"modified":"2019-04-04T17:14:56","modified_gmt":"2019-04-04T11:44:56","slug":"create-login-form-using-codeigniter-framework","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/create-login-form-using-codeigniter-framework\/","title":{"rendered":"CREATE LOGIN FORM USING CODEIGNITER  FRAMEWORK"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">CREATE LOGIN FORM IN CODEIGNITER<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">Date :03\/04\/2019<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we will help you in creating a simple login form using codeigniter framework.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/-1GM6d98p9Jk\/VYYF5thMvuI\/AAAAAAAAFs4\/jsucNlqXYxY\/25-free-css-html-login-form-templates.jpg?imgmax=1600\" alt=\"Related image\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Pre-requesties<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">we have to create database and table. Firstly, create database and name it  as \u2018form\u2019. similarly, create a table named \u2018register\u2019. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Database Config Settings<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In order to connect with the database, the below instructions must be followed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The file is located at <strong>application\/config\/database.php.<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$db['default'] = array(\n\t'dsn'\t=> '',\n\t'hostname' => 'localhost',\n\t'username' => 'root',\n\t'password' => '',\n\t'database' => 'form',\n\t'dbdriver' => 'mysqli',\n\t'dbprefix' => '',\n\t'pconnect' => FALSE,\n\t'db_debug' => (ENVIRONMENT !== 'production'),\n\t'cache_on' => FALSE,\n\t'cachedir' => '',\n\t'char_set' => 'utf8',\n\t'dbcollat' => 'utf8_general_ci',\n\t'swap_pre' => '',\n\t'encrypt' => FALSE,\n\t'compress' => FALSE,\n\t'stricton' => FALSE,\n\t'failover' => array(),\n\t'save_queries' => TRUE\n);\n\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Controller (application\/controllers\/Welcome.php)<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Controller is a process which get the input request from user, communicates with <strong>Model<\/strong> and then loads appropriate <strong>Views<\/strong> file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the below Controller class, we have functions for different tasks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">=>load_login()- This function load the login page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">=>login_validate()-Fetch the data and pass the values to model.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public function load_login()\n{\n    $this->load->view('login.php');  \n}\n public function login_validate()\n    {\n\n      $this->load->library('form_validation');\n      $this->form_validation->set_rules('firstname', 'first_name', 'required');\n      $this->form_validation->set_rules('password', 'password', 'required');\n      if ($this->form_validation->run())\n      {\n        $username=$this->input->post('firstname');\n        $password=$this->input->post('password');\n        $this->load->model('Insert_model');\n        if($var1=$this->Insert_model->check_login($username,$password))\n        {\n            echo \"logged in successfully\";\n        }\n        else\n        {\n          $this->session->set_flashdata('error','Invalied username and password');\n          redirect('Welcome\/load_login');\n        }\n      }\n      else\n      {\n         echo json_encode($this->form_validation->error_array());\n        $this->load->view('login.php');\n      }\n      \n    }<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Model (application\/models\/Insert_model.php)<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>To check the login,<\/strong><br>check_login-> function fetches register item by it\u2019s username and password<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> public function check_login($username,$password)\n  {\n    $this->db->where('first_name',$username);\n    $this->db->where('password',$password); \n    $query=$this->db->get('register');\n\n    if($query->num_rows()>0)\n    {\n       \n       return $query->row();\n    }\n    else\n    {\n      return false;\n    }\n  }<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Index View (application\/views\/login.php)<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This view file is called by load_login() function of our Controller class.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;body>\n&lt;center>\n\t\t&lt;h5>Login Form&lt;\/h5>\n\t&lt;form role=\"form\" method=\"post\" action=\"&lt;?php echo site_url('Welcome\/login_validate');?>\">\n\t&lt;table>\n\t\t\t&lt;tr>&lt;td>user name&lt;\/td>&lt;td>&lt;input type=\"text\" name=\"firstname\">&lt;\/td>&lt;br>&lt;\/tr>\n  \t\t\t&lt;tr>&lt;td>Password&lt;\/td>&lt;td>&lt;input type=\"Password\" name=\"password\">&lt;\/td>&lt;br>&lt;\/tr>\n  \t\t\t&lt;tr>&lt;td>&lt;input type = \"submit\" name=\"submit\"\/>&lt;\/td>&lt;\/tr>\n\t\t\t&lt;\/table>\n\t&lt;\/form>\n&lt;\/center><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Conclusion: <\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"> If you enter the correct login details it will display the message like \u201clogged in successfully\u201d. Otherwise it will show as  \u201cInvalid username and password\u201d. That&#8217;s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\n\nThanks for using pheonixsolutions.\n\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You find this tutorial helpful? Share with your friends to keep it alive.<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>CREATE LOGIN FORM IN CODEIGNITER Date :03\/04\/2019 In this article, we will help you in creating a simple login form [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[604],"class_list":["post-4078","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-login-form","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-13M","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=4078"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4078\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=4078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=4078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=4078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}