CodeIgniter Forums
Session Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Session Problem (/showthread.php?tid=49702)



Session Problem - El Forum - 02-29-2012

[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>
      &lt;input type="text" value="" class="normalinput" name="username" id="username"&gt;
      <label for="password">Şifreniz:</label>
      &lt;input type="password" class="normalinput" value="" name="password" id="password"&gt;
      <span class="bigsubmitwbtn yellow fright"><span class="bigsubmitwbtn_left"></span>&lt;input type="submit" class="bigbutton" name="submit" value="Giriş"&gt;&lt;/span>
      &lt;/form&gt;
     </div>



However as declered in main_page function , it goes directly else statement and prints Error Why ?


Session Problem - El Forum - 02-29-2012

[eluser]Mauricio de Abreu Antunes[/eluser]
What does happen when you print $userID?