Validating a form hiding controller from URL Codeigniter - php

I'm facing a problem when trying to create a simple login system. This is how it works and shows what my problem is.
The login page contains a simple form, and opens a form to the controller 'Verify_login'. This Verify_login controller does some basic form validations, and then queries the database to check if the user entered correct credentials. When this form is submitted, it automatically directs the user to website.com/verify_login, while I would like it to remain website.com/login. I am not able to solve this problem using the routes file, because this causes the two pages to be both redirected to the same page. Does anyone have a solution to this? I'm using the Codeigniter framework.
login.php
<div class="content-block">
<h1>Login</h1>
<div class="content-inner-block">
<?php echo validation_errors(); ?>
<?php echo form_open('Verify_login'); ?>
<div class="login wrap">
<input type="text" name="username" id="user" placeholder="Username">
<input type="password" name="password" id="pass" placeholder="**********">
<input type="submit" value="Log in">
</div>
<?php echo form_close("\n")?>
</div>
Verify_login.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Verify_login extends CI_Controller{
public function index(){
$this->load->model('User_model');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE){
$this->load->view('pages/login');
return false;
}
$result = $this->User_model->login($this->input->post('username'), $this->input->post('password'));
if($result){
echo 'loggedin';
} else {
echo 'wrong';
}
}
}
?>

Related

$_POST is null in codeigniter

when I'm login, the login controller will handle my login but Why my $_post in the controller is always false? (I know because is null but why is null?) and then is make me can't login to my home page. please, someone, help me
I have a controller like this
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->model('M_login');
}
public function index() {
//if user has log-in, redirect to somewhere
if($this->session->userdata('loggedin')) {
redirect('home');
//else go to login form
} else {
if($_POST["username"]) {
echo $this->M_login->ceklogin();
redirect('login');
} else {
//if user input the wrong email/data
$this->session->set_flashdata("msg_login", "Wrong credentials.");
redirect('home/login');
}
}
}
}
This is my view
<?php
$this->load->view('parts/header');
?>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">WoW Page</h3>
</div>
<div class="panel-body">
<form action="<?php echo base_url();?>index.php/login" method="POST">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Username" name="username" type="text" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="password" type="password" value="">
</div>
<?php if ($this->session->flashdata('msg_login') != '') { ?>
<div class="alert alert-danger alert-dismissible" role="alert">
<center><i class="fa fa-warning" aria-hidden="true"></i> <?php echo $this->session->flashdata('msg_login'); ?></center>
</div>
<?php } ?>
<!-- Change this to a button or input when using this as a form -->
<input type="submit" class="btn btn-lg btn-danger btn-block" value="Login">
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- jQuery -->
<script src="<?php echo base_url();?>assets/bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<?php echo base_url();?>assets/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="<?php echo base_url();?>assets/bower_components/metisMenu/dist/metisMenu.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="<?php echo base_url();?>assets/dist/js/sb-admin-2.js"></script>
</body>
</html>
And this is my model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class M_login extends CI_Model {
// cek login
public function ceklogin() {
$query = $this->db->get_where('admin', array(
'username'=>$this->input->post('username'),
//password converted to md5
'password'=>md5($this->input->post('password'))
));
$user = $query->row();
if(count($user) != 0) {
//setting isi session
$sesi = array(
'admin_id'=>$user->admin_id,
'username'=>$user->username,
'level'=>$user->level,
'loggedin'=>true
);
$this->session->set_userdata($sesi);
} else {
$data = array('loggedin'=>false);
}
}
}
?>
Thank You
Thank You
Thank You
There are several problems. First one is that your model does not return anything that the controller can use. Here are my thoughts on how the model should be done.
public function ceklogin($user_name, $password)
{
$user = $this->db
->select('admin_id, username, level')
->get_where('admin', array('username'=>$username, 'password'=>md5($password)))
->row_array();
if( ! empty($user))
{
$user['loggedin'] = true; //add 'loggedin' to $user array
$this->session->set_userdata($user);
return TRUE;
}
$_SESSION['loggedin'] = false;
return FALSE;
}
Notice that there are two arguments to the function - $user name and $password. These need to be provided by the controller. Notice that ceklogin() returns TRUE or FALSE depending on if a row is found in the database.
I did not change the password hashing - BUT YOU SHOULD. Use the functions that #RiggsFolly told you about in the comments. You should also look into sanitizing and validating the inputs. Never trust user input!
Notice the database call returns a row_array() results. This will be the exact data structure you wanted for session data. That means you do not have to build an array for set_userdata() because the database made it for you.
Here is the revised index() function.
public function index()
{
//if user has log-in, redirect to somewhere
if($this->session->userdata('loggedin'))
{
redirect('home');
}
// get the inputs so they can be passed to the model
$user_name = $this->input->post('username');
$password = $this->input->post('password');
// if we have inputs, check for valid username & password
if($user_name && $password)
{
if($this->M_login->ceklogin($user_name, $password))
{
// model returned true
redirect('home'); //if 'home' is where valid users go
}
}
// If not all inputs (null/empty $_POST)
// or the wrong inputs (ie. model returned false)
$this->session->set_flashdata("msg_login", "Wrong credentials.");
redirect('home/login');
}
I removed many (all) the else statements. They were not needed because all the if blocks end in a call to redirect() and that function calls exit; meaning that a call to redirect() never returns to where it was called from.
You should be using the CodeIgniter Validation Library instead of the crude construct
if($user_name && $password)
But that's better than nothing.

Can't use Ion Auth's login method in another controller

I added controllers/Site.php , views/site/login.php to my project but when I submit login form i always get */application/views/site/login#
Do anyone knows why? whats the problem?
here is my Site.php :
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Site extends MY_Controller {
function __construct() {
parent::__construct();
$this->load->library('ion_auth');
$this->load->library('form_validation');
$this->load->helper('url');
$this->load->helper('string');
$this->load->database();
$this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));
$this->lang->load('auth');
$this->load->helper('language');
$this->data['pageTitle'] = $this->lang->line('login_page_title');
}
//redirect if needed, otherwise display the user list
function index() {
if (!$this->ion_auth->logged_in()) {
//redirect them to the login page
redirect('site/login', 'refresh');
} else if (!$this->ion_auth->is_admin()) { //remove this elseif if you want to enable this for non-admins
//redirect them to the home page because they must be an administrator to view this
return show_error('You must be an administrator to view this page.');
}
}
//log the user in
function login() {
$this->data['title'] = "Login";
//validate form input
$this->form_validation->set_rules('identity', 'Identity', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == true) {
//check to see if the user is logging in
//check for "remember me"
$remember = (bool) $this->input->post('remember');
if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember)) {
//if the login is successful
//redirect them back to the home page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect('/', 'refresh');
} else {
//if the login was un-successful
//redirect them back to the login page
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('site/login', 'refresh'); //use redirects instead of loading views for compatibility with MY_Controller libraries
}
}
$this->_render_page('site/login', $this->data);
}
}
And here is my simple login.php :
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Login</h1>
<form role="form" action="#" method="post">
<div class="input-group">
<input type="email" id="identity" name="identity" placeholder="Your email address" value="admin#mail.com">
</div>
<div class="input-group">
<input type="password" id="password" name="password" placeholder="Your password" value="password">
</div>
<div class="checkbox-group">
<input type="checkbox" value="1" id="remember" name="remember" data-toggle="checkbox">
<label for="remember">Remember Me</label>
</div>
<button type="submit">Log me in</button>
</form>
</body>
</html>
This action="#" looks very strange. I think you should change this with action='/site/login'. You don't need use base_url() as commented above. Related path should be enough.

Codeigniter multiple URL's while running form_validation->run()

I have a register_page.php file in the views folder which is just a register form. When you click the register button, and say the password doesn't match, it should that the password doesn't match after clicking the submit button. However, after you type the password and it still doesn't match, it doesn't do anything, it just duplicates the url.
For example
URL when the password doesn't match: http://localhost/dayone/user/register_user
URL when when the password still doesn't match: http://localhost/dayone/user/user/register_user
At this point, the form is empty, all the values are removed and when you press enter without filling anything in, it doesn't show any error, but the URL says: http://localhost/dayone/user/user/register_user
What's causing this?
My user.php controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller {
public function index()
{
$this->load->view('includes/header');
$this->load->view('register_page');
$this->load->view('includes/footer');
}
public function register_user () {
$this->load->library('form_validation');
//rules to become a registered user
$this->form_validation->set_rules('first_name', 'First Name', 'required|trim|min_length[3]|max_length[20]|xss_clean');
$this->form_validation->set_rules('last_name', 'Last Name', 'required|trim|min_length[3]|max_length[20]|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'required|trim|min_length[6]|max_length[50]|valid_email|is_unique[users.email]|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'required|trim|min_length[6]|max_length[50]|matches[password_conf]|xss_clean');
$this->form_validation->set_rules('password_conf', 'Confirm Password', 'required|trim|min_length[6]|max_length[50]|xss_clean');
if ($this->form_validation->run() == FALSE) {
//user didn't validate, send back to login form and show errors
$this->load->view('includes/header');
$this->load->view('register_page');
$this->load->view('includes/footer');
} else {
//successful registration
$this->load->view('login');
}
}
}
My resister_page.php (with the register form):
<!DOCTYPE html>
<html lang="en">
<body>
<div id="container" class="page">
<div>
<section class="container">
<h2 class="block-title block-title--bottom">Login</h2>
<div class="login">
<?php echo validation_errors('<p class="alert-market">'); ?>
<form class="contact" id="contact-form" name="contact-form" method="post" action="user/register_user">
<!--- FIRST NAME --->
<input class="contact__field" value="<?php echo set_value('first_name'); ?>" name="first_name" id="first_name" type="text" placeholder="First Name">
<!--- LAST NAME --->
<input class="contact__field" value="<?php echo set_value('last_name'); ?>" name="last_name" id="last_name" type="text" placeholder="Last Name">
<!--- EMAIL --->
<input class="contact__field" value="<?php echo set_value('email'); ?>" name="email" id="email" type="email" placeholder="Email">
<!--- PASSWORD --->
<input class="contact__field" name="password" id="password" type="password" placeholder="Password">
<!--- CONFIRM PASSWORD --->
<input class="contact__field" name="password_conf" id="password_conf" type="password" placeholder="Confirm Password">
<a class="login__callback" href="#">Forgot password?</a>
<input class="btn btn--decorated btn-warning login__btn" value = "Login" name="submit" type="submit">
<?php echo form_close(); ?>
</div>
</section><!-- end container -->
</div>
</div><!-- /#page -->
</body>
</html>
I have no idea what is causing this.
Instead of this one:
<form class="contact" id="contact-form" name="contact-form" method="post" action="user/register_user">
You can use this one:
<?php echo form_open('user/register_user');?>
Which is also equal to this:
<form method="post" accept-charset="utf-8" action="http://localhost/dayone/user/register_user"/>
Assuming that your base_url in your config.php is equal to:
$config['base_url'] = 'http://localhost/dayone/';
I suggest you invest time in reading more about CodeIgniter's User Guide here.
EDIT:
Do not forget to load your form and url helpers too. You can load them in autoload.php in application/config
$autoload['helper'] = array("url","form");
Or
Make a function __contruct() and load your helpers and models there.
Example:
function __construct()
{
parent::__construct();
$this->load->model('sample_model');
$this->load->helper('url');
$this->load->helper('form');
}
Constructors are useful if you need to set some default values, or run
a default process when your class is instantiated. Constructors can't
return a value, but they can do some default work.
--From CodeIgniter - Controllers under Class Constructors
First use form helper to form open
<?php echo form_open('user/register_user');?>
Then change your match password rules like(match confirm password to password):-
$this->form_validation->set_rules('password', 'Password', 'required|trim|min_length[6]|max_length[50]|xss_clean');
$this->form_validation->set_rules('password_conf', 'Confirm Password', 'required|trim|min_length[6]|max_length[50]|matches[password]|xss_clean');
Then your else part should be a redirect not load a view again like
else {
// success register
redirect('login');
}

Incorrect use of the CodeIgniter form_validation() function throwing fatal error

I'm trying to apply CodeIgniter's form validation feature for an input form in one of my view pages. In that form, all fields are required. If all the fields are successfully filled up and then if the user clicks the submit button, it will redirect to another view page with the list of entries. If any field is left empty, validation messages will be displayed.
Here's my form in first view page - employee_add.php:
<div id="content" class="box">
<form action="<?php echo base_url();?>index.php/employee_adds/insert_employee_db" method="post">
<?php echo validation_errors(); ?>
<fieldset>
<legend id="add_employee_legend">Add New Employee</legend>
<div>
<label id= "emp_id_add_label">Employee ID:</label>
<input type="text" name="emp_id" id = "employee_id_add" placeholder="Employee ID"/>
</div>
<div>
<label id= "emp_name_add_label">Employee Name:</label>
<input type="text" name="emp_name" id = "employee_name_add" placeholder="Employee Name"/>
</div>
<input type="submit" name="submit" id = "employee_info_submit" value="Send"/>
</fieldset>
</form>
</div>
Here's my controller - employee_adds.php:
<?php
if ( ! defined('BASEPATH')){ exit('No direct script access allowed');}
class Employee_adds extends CI_Controller
{
function __construct()
{
parent::__construct();
#$this->load->helper('url');
$this->load->model('employee_model');
}
//Show all Employees or validate employees
public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('emp_id', 'Employee ID', 'required');
$this->form_validation->set_rules('emp_name', 'Employee Name', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('admin_logins/employee_add');
}
else
{
$data['employee_list'] = $this->employee_model->get_all_employees();
$this->load->view('admin_logins/employee_list');
}
}
//Insert an employee
public function insert_employee_db()
{
$edata['emp_id'] = $this->input->post('emp_id');
$edata['emp_name'] = $this->input->post('emp_name');
$res = $this->employee_model->insert_employee($edata);
if($res)
{
header('location:'.base_url()."index.php/employee/".$this->index());
}
}
}
?>
Here's controller for master page named admin_logins.php:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Admin_logins extends CI_Controller
{
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('admin_logins/index');
}
function employee()
{
$this->load->view('admin_logins/employee_add');
}
}
Here's my model - employee_model.php:
<?php
class Employee_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
//To retrieve all employees
public function get_all_employees()
{
$query = $this->db->get('employee');
return $query->result();
}
//To add a new employee to the database
public function insert_employee($data)
{
return $this->db->insert('employee', $data);
}
}
?>
Another view page named employee_list.php is going to load the list of successful entries in its central div:
<div id="content" class="box">
<table id = "employee_list_table" width="600">
<tr>
<th scope="col">Employee Id</th>
<th scope="col">Employee Name</th>
</tr>
<?php foreach ($employee_list as $e_key){ ?>
<tr>
<td><?php echo $e_key->emp_id; ?></td>
<td><?php echo $e_key->emp_name; ?></td>
</tr>
<?php }?>
</table>
</div>
Whenever I try to run the employee_add.php view page, I get the following error:
Fatal error: Call to undefined function validation_errors() in C:\wamp\www\CI\application\views\admin_logins\employee_add.php
From what I'm guessing, it may be due to one of the two following reason:
My code designing and layout was incorrect (disorganized coding in views, controller and model)
My code syntax was incorrect (most likely in the uses of form and form validation)
Or maybe, there are other reasons. I just can't figure out why, and exactly where in my code the errors occurred.
EDIT-1: As per user Ghost's solution, I've loaded the form_validation library in my admin_logins/employee method in controller - admin_logins.php. The fatal PHP error's gone, but still the validation is not working. As soon as I click submit button after keeping those fields empty, instead of validation message, I get the following error message:
A Database Error Occurred
Error Number: 1146
La table 'ci_test.employee' n'existe pas
INSERT INTO `employee` (`emp_id`, `emp_name`) VALUES ('', '')
Filename: C:\wamp\www\CI\system\database\DB_driver.php
It seems I still have more syntactical mistakes in my code.
It seems that both:
Employee_adds -> index() and Admin_logins ->employee() share the same view file:
'admin_logins/employee_add'
And when you put <?php echo validation_errors(); ?> What triggers the error is that looking on Admin_logins ->employee()
It seems that $this->load->library('form_validation'); is not loaded:
function employee()
{
$this->load->view('admin_logins/employee_add');
}
So by the time you access admin_logins/employee, it causes the error since the validation library hasn't been initialized.

User registration with CodeIgniter

I'm trying to build a registration system with CodeIgniter. I have a controller called Register with the following code:
class Register extends CI_Controller {
public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
$this->form_validation->set_rules('username', 'username', 'required|min_length[3]|max_length[12]|trim');
$this->form_validation->set_rules('password', 'password', 'required|min_length[2]|md5');
$this->form_validation->set_rules('email', 'email', 'required|valid_email|trim');
$this->form_validation->set_rules('artist', 'artist', 'max_length[32]|trim');
$this->form_validation->set_rules('captcha', 'CAPTCHA', 'required|trim');
$this->load->view('header');
if(!$this->form_validation->run())
{
$this->load->view('register_form');
}
else
{
$this->load->view('register_done');
}
$this->load->view('footer');
}
}
So far so good. If I go to the register page I get the registration form displayed. If I send the form and it passes the form validation checks, I get the success page, if the form has errors, I get the form back with some error messages.
Now what I want to do is the database stuff. I have some idea of how I can get the POST values from the registration form into my database, but no clue how I can check if a username or email already exists, and if so, display that error on the registration form. Here's my registration form view:
<?php $this->load->helper('form'); ?>
<?php echo form_open('register'); ?>
<ul id="register">
<ul>
<h3>Account information</h3>
<li>
<label for="username">Choose a username</label>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" />
<span class="desc">The name you'd like to be known by</span>
<?php echo form_error('username'); ?>
</li>
<li>
<label for="password">Pick a password</label>
<input type="password" name="password" />
<span class="desc">The best passwords are random and more than 6 characters long</span>
<?php echo form_error('password'); ?>
</li>
<li>
<label for="email">Enter your valid email address</label>
<input type="text" name="email" value="<?php echo set_value('email'); ?>" />
<span class="desc">We'll send you an activation email</span>
<?php echo form_error('email'); ?>
</li>
</ul>
<ul>
<h3>About you</h3>
<li>
<label for="band">Who's your favorite artist?</label>
<input type="text" name="artist" value="<?php echo set_value('artist'); ?>" />
<span class="desc">Don't put Lady GaGa.</span>
<?php echo form_error('artist'); ?>
</li>
</ul>
<ul>
<h3>Security question</h3>
<li>
<label for="captcha">Enter the letters you see in the image</label>
<?php $this->load->helper('captcha');
$cap = create_captcha(array('img_path' => './captcha/', 'img_url' => 'http://localhost/captcha/', 'img_width' => 200, 'img_height' => 30));
$data = array('captcha_time' => $cap['time'], 'ip_address' => $this->input->ip_address(), 'word' => $cap['word']);
$query = $this->db->insert_string('captcha', $data);
$this->db->query($query);
echo $cap['image']; ?>
<input type="text" name="captcha" />
<?php echo form_error('captcha'); ?>
</li>
</ul>
<ul>
<h3 class="submit">
<input type="submit" value="Register" />
</h3>
</ul>
</ul>
<?php echo form_close(); ?>
As you can see, I'm taking advantage of the form_error() function of CI to display form errors right under the field, and I would like the "username already exists" error to also be displayed under the username field.
Can anyone provide some help? Even a nudge in the right direction?
Thanks!
I would strongly urge you to think about using another library that already does this very well: TankAuth. TankAuth is easily modifiable and offers email confirmation, very secure password hashing, a solid database schema, and very clean code.
There's no reason to reinvent the wheel, especially when it comes to something that's very hard to get right like user authentication.
EDIT:
For example, here's everything TankAuth provides security-wise that you'd have to code yourself (if you cared about security) - how much time would that take?
Using phpass library for password hashing (instead of unsafe md5).
Counting login attempt for bruteforce preventing (optional). Failed login attempts determined by IP and by username.
Logging last login IP-address and time (optional).
CAPTCHA for registration and repetitive login attempt (optional).
Unactivated accounts and forgotten password requests auto-expire.
You need to create a model for your controller.
Your model would look like this:
class Register_model extends CI_Model {
function register_user()
{
$data['username'] = $this->input->post('username');
$data['password'] = sha1($this->input->post('password'));
... (your other post data) ...
$this->db->insert('users', $data);
}
}
In your controller you will call the model this way:
$this->load->model('Register_model');
and the method goes here:
else
{
$this->Register_model->register_user();
$this->load->view('register_done');
}
If you want to check if the username is available, you simply put SELECT query on the first lines of the register_user() method (function).
To do the check you should have functions in your model that can look up those types of things for you:
class Model{
function getUserByEmail($email);
function getUserByUsername($username);
...
}
Then in your controller you can call these methods
...
$result = $model->getUserByEmail($_POST['email']); // You'll need to sanitize your POST
if(count($result) > 0){
// Sent error about email already existing and flag to not insert/update user
}
...
The easiest solution in CodeIgniter is to use a callback function as one of the rules in your form validation.
I've used this method myself to check the username and e-mail.
Here's the docs for it.
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('form');
// Load session library
$this->load->library('session');
// Load database
$this->load->model('User_model');
}
public function index()
{
$this->load->view('index');
}
public function project()
{
$this->data['posts'] = $this->User_model->getPosts(); // calling Post model method getPosts()
$this->load->view('tables', $this->data);
// $this->load->aview('project');
}
public function get_project()
{
$this->User_model->get_project($data);
}
public function signin()
{
$data = array(
'email' => $this->input->post('email'),
'password' => $this->input->post('password')
);
$this->User_model->signin($data);
}
public function logout()
{
$this->session->unset_userdata($_SESSION['email']);
// $this->session->sess_destroy();
redirect('User');
}
public function signup()
{
$data = array(
'name' => $this->input->post('name'),
'phone' => $this->input->post('phone'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password')
);
if($this->User_model->signup($data))
{
echo "no insert";
}
else
{
$this->load->view('index', $data);
}
}
}
<?php
Class User_model extends CI_Model {
function __construct() {
parent::__construct();
$this->load->library('session');
}
public function signup($data)
{
$this->db->insert('user_signup',$data);
}
public function getPosts()
{
$this->db->select("*");
$this->db->from('user_data');
$query = $this->db->get();
return $query->result();
}
public function signin($data)
{
$this->db->where('email',$data['email']);
$this->db->where('password',$data['password']);
$query=$this->db->get('user_signup');
if($query->num_rows()==1){
$_SESSION['email'] = $data['email'];
$this->load->view('popup',$data);
return true;
}
else{
echo "no";
return false;
}
}
}

Categories