Advertisement
Guest User

Untitled

a guest
Feb 18th, 2017
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.57 KB | None | 0 0
  1. A PHP Error was encountered
  2.  
  3. Severity: Warning
  4.  
  5. Message: ini_set(): A session is active. You cannot change the session module's ini settings at this time
  6.  
  7. Filename: Session/Session.php
  8.  
  9. Line Number: 316
  10.  
  11. Backtrace:
  12.  
  13. File: C:xampphtdocsgenstoreadminapplicationcontrollersuser_authentication.php
  14. Line: 8
  15. Function: __construct
  16.  
  17. File: C:xampphtdocsgenstoreadminindex.php
  18. Line: 315
  19. Function: require_once
  20.  
  21. ________________________________________________________________________________________________________________________________
  22.  
  23. A PHP Error was encountered
  24.  
  25. Severity: Notice
  26.  
  27. Message: A session had already been started - ignoring session_start()
  28.  
  29. Filename: Session/Session.php
  30.  
  31. Line Number: 143
  32.  
  33. Backtrace:
  34.  
  35. File: C:xampphtdocsgenstoreadminapplicationcontrollersuser_authentication.php
  36. Line: 8
  37. Function: __construct
  38.  
  39. File: C:xampphtdocsgenstoreadminindex.php
  40. Line: 315
  41. Function: require_once
  42.  
  43. <?php
  44.  
  45. session_start(); //we need to start session in order to access it through CI
  46.  
  47. Class User_Authentication extends CI_Controller {
  48.  
  49. public function __construct() {
  50. parent::__construct();
  51.  
  52. // Load form helper library
  53. $this->load->helper('form_helper');
  54.  
  55. // Load form validation library
  56. $this->load->library('Form_validation');
  57.  
  58. // Load session library
  59. $this->load->library('Session');
  60.  
  61. // Load database
  62. $this->load->model('login_database');
  63. }
  64.  
  65. // Show login page
  66. public function index() {
  67. $this->load->view('login_form');
  68. }
  69.  
  70. // Show registration page
  71. public function user_registration_show() {
  72. $this->load->view('registration_form');
  73. }
  74.  
  75. // Validate and store registration data in database
  76. public function new_user_registration() {
  77.  
  78. // Check validation for user input in SignUp form
  79. $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
  80.  
  81. $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
  82. if ($this->form_validation->run() == FALSE) {
  83. $this->load->view('registration_form');
  84. } else {
  85. $data = array(
  86. 'user_name' => $this->input->post('username'),
  87.  
  88. 'user_password' => $this->input->post('password')
  89. );
  90. $result = $this->login_database->registration_insert($data);
  91. if ($result == TRUE) {
  92. $data['message_display'] = 'Registration Successfully !';
  93. $this->load->view('login_form', $data);
  94. } else {
  95. $data['message_display'] = 'Username already exist!';
  96. $this->load->view('registration_form', $data);
  97. }
  98. }
  99. }
  100.  
  101. // Check for user login process
  102. public function user_login_process() {
  103.  
  104. $this->form_validation->set_rules('username', 'username', 'trim|required|xss_clean');
  105. $this->form_validation->set_rules('password', 'password', 'trim|required|xss_clean');
  106.  
  107. if ($this->form_validation->run() == FALSE) {
  108. if(isset($this->session->userdata['logged_in'])){
  109. $this->load->view('view_all_produk');
  110. }else{
  111. $this->load->view('login_form');
  112. }
  113. } else {
  114. $data = array(
  115. 'username' => $this->input->post('username'),
  116. 'password' => $this->input->post('password')
  117. );
  118. $result = $this->login_database->login($data);
  119. if ($result == TRUE) {
  120.  
  121. $username = $this->input->post('username');
  122. $result = $this->login_database->read_user_information($username);
  123. if ($result != false) {
  124. $session_data = array(
  125. 'username' => $result[0]->username,
  126. );
  127. // Add user data in session
  128. $this->session->set_userdata('logged_in', $session_data);
  129. $this->load->view('view_all_produk');
  130. }
  131. } else {
  132. $data = array(
  133. 'error_message' => 'Invalid Username or Password'
  134. );
  135. $this->load->view('login_form', $data);
  136. }
  137. }
  138. }
  139.  
  140. // Logout from admin page
  141. public function logout() {
  142.  
  143. // Removing session data
  144. $sess_array = array(
  145. 'username' => ''
  146. );
  147. $this->session->unset_userdata('logged_in', $sess_array);
  148. $data['message_display'] = 'Successfully Logout';
  149. $this->load->view('login_form', $data);
  150. }
  151.  
  152. }
  153.  
  154. ?>
  155.  
  156. <html>
  157. <?php
  158. if (isset($this->session->userdata['logged_in'])) {
  159.  
  160. header("location: http://localhost/genstore/admin/index.php/user_authentication/user_login_process ");
  161. }
  162. ?>
  163. <head>
  164. <title>Login Form</title>
  165. <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>/css/style.css">
  166. <link href='http://fonts.googleapis.com/css family=Source+Sans+Pro|Open+Sans+Condensed:300|Raleway' rel='stylesheet' type='text/css'>
  167. </head>
  168. <body>
  169. <?php
  170. if (isset($logout_message)) {
  171. echo "<div class='message'>";
  172. echo $logout_message;
  173. echo "</div>";
  174. }
  175. ?>
  176. <?php
  177. if (isset($message_display)) {
  178. echo "<div class='message'>";
  179. echo $message_display;
  180. echo "</div>";
  181. }
  182. ?>
  183. <div id="main">
  184. <div id="login">
  185. <h2>Login Form</h2>
  186. <hr/>
  187. <?php echo form_open('user_authentication/user_login_process'); ?>
  188. <?php
  189. echo "<div class='error_msg'>";
  190. if (isset($error_message)) {
  191. echo $error_message;
  192. }
  193. echo validation_errors();
  194. echo "</div>";
  195. ?>
  196. <label>UserName :</label>
  197. <input type="text" name="username" id="name" placeholder="username"/><br / <br />
  198. <label>Password :</label>
  199. <input type="password" name="password" id="password" placeholder="**********"/><br/><br />
  200. <input type="submit" value=" Login " name="submit"/><br />
  201. <a href="<?php echo base_url() ?>index.php/user_authentication/user_registration_show">To SignUp Click Here</a>
  202. <?php echo form_close(); ?>
  203. </div>
  204. </div>
  205. </body>
  206. </html>
  207.  
  208. <?php
  209.  
  210. Class Login_Database extends CI_Model {
  211.  
  212. // Insert registration data in database
  213. public function registration_insert($data) {
  214.  
  215. // Query to check whether username already exist or not
  216. $condition = "user_name =" . "'" . $data['user_name'] . "'";
  217. $this->db->select('*');
  218. $this->db->from('user_login');
  219. $this->db->where($condition);
  220. $this->db->limit(1);
  221. $query = $this->db->get();
  222. if ($query->num_rows() == 0) {
  223.  
  224. // Query to insert data in database
  225. $this->db->insert('user_login', $data);
  226. if ($this->db->affected_rows() > 0) {
  227. return true;
  228. }
  229. } else {
  230. return false;
  231. }
  232. }
  233.  
  234. // Read data using username and password
  235. public function login($data) {
  236.  
  237. $condition = "username =" . "'" . $data['username'] . "' AND " . "password =" . "'" . $data['password'] . "'";
  238. $this->db->select('*');
  239. $this->db->from('admin');
  240. $this->db->where($condition);
  241. $this->db->limit(1);
  242. $query = $this->db->get();
  243.  
  244. if ($query->num_rows() == 1) {
  245. return true;
  246. } else {
  247. return false;
  248. }
  249. }
  250.  
  251. // Read data from database to show data in admin page
  252. public function read_user_information($username) {
  253.  
  254. $condition = "username =" . "'" . $username . "'";
  255. $this->db->select('*');
  256. $this->db->from('admin');
  257. $this->db->where($condition);
  258. $this->db->limit(1);
  259. $query = $this->db->get();
  260.  
  261. if ($query->num_rows() == 1) {
  262. return $query->result();
  263. } else {
  264. return false;
  265. }
  266. }
  267.  
  268. }
  269.  
  270. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement