[eluser]Unknown[/eluser]
i try to do login pages with session in Codeigniter.
In order to do that , i made a model
Code:
function girisKontrol($username, $password) {
$sha1_password = sha1($password);
$query = "SELECT id FROM pasaj_register WHERE username = ? and password = ?";
$result = $this->db->query($query, array($username, $sha1_password));
if ($result->num_rows() == 1)
return $result->row(0)->id;
else
return false;
}
and in giris controller i made a function called giris
Code:
public function giris() {
extract($_POST);
$userID = $this->giris->girisKontrol($username,$password);
echo $userID;
if (!$userID) {
$this->session->set_flashdata('login error',TRUE);
redirect('giris/giris');
} else {
$this->session->set_userdata(array(
'logged_in' => TRUE,
'userID' => $userID));
redirect('welcome_message');
}
}
in the same controller i made one function more:
Code:
public function main_page()
{
if ($this->session->userdata('logged_in'))
echo "Logged in";
else
echo "Error";
}
and use all of these in view
Code:
<form method="POST" action="http://localhost:81/pasaj/giris/main_page/" name="flogin" autocomplete="off">
<label for="username"><b>Kullanıcı adı</b> ya da <b>e-posta</b> adresiniz:</label>
<input type="text" value="" class="normalinput" name="username" id="username">
<label for="password">Şifreniz:</label>
<input type="password" class="normalinput" value="" name="password" id="password">
<span class="bigsubmitwbtn yellow fright"><span class="bigsubmitwbtn_left"></span><input type="submit" class="bigbutton" name="submit" value="Giriş"></span>
</form>
</div>
However as declered in main_page function , it goes directly else statement and prints Error Why ?