Welcome Guest, Not a member yet? Register   Sign In
how to create a login ...
#1

[eluser]atno[/eluser]
Hello all,

I'm new to CI and i was wondering how can i translate the following code to CI code.
Code:
session_start();
// Assign the variables
$form_username = $_REQUEST['username'];
$form_password = $_REQUEST['password'];
$md5_form_password = md5($form_password);

// Initiate database connection
$dbCon = mysql_connect($CONF_DB_HOST,$CONF_DB_USER,$CONF_DB_PASS)
                or die('Could not connect: ' . mysql_error());
// Select the database
mysql_select_db($CONF_DB_NAME) or die('Could not select database');

// Our query
$sql = "SELECT *
        FROM users
        WHERE username = '$form_username'
                AND password ='$md5_form_password'";

// Get the results using $sql query
$res = mysql_query($sql)
        or die('SQL query failed: ' . mysql_error());
// Fetch the row
$row = mysql_fetch_row($res);

// Test the $row
if ($row) {
        $_SESSION['logged_in'] = true;
        $_SESSION['username'] = $form_username;
        header('Location: index.php');
        exit;
}else {
        echo('Incorrect username or password<br>');
}

Thanks in advance and sorry for the long post

Antonis
#2

[eluser]LuckyFella73[/eluser]
Have a look at this post:
http://ellislab.com/forums/viewthread/65789/
#3

[eluser]Sarfaraz Momin[/eluser]
You can check this post for all your queries regarding login system

Login Validation

Good Day !!!
#4

[eluser]atno[/eluser]
Big thanks to both of you Smile

Atno




Theme © iAndrew 2016 - Forum software by © MyBB