User Login

#1
[eluser]GamingFusion[/eluser]
I have made a simple Login Script that asks the user for their username and password.

Heres my problem, when i go to the login page it doesn't display. I think it has somehting to do with my if statement at the top but it should work.

here is my code
----View----
Code:
<?php
$this->database->checkLogin();

if ($loggedIn == FALSE)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
<h1>&lt;?=$heading?&gt;</h1>
<hr />
  
&lt;?php echo validation_errors(); ?&gt;

&lt;?=form_open('theater/checkLogin');?&gt;

<table>
    <tr>
        <td>Username: </td><td>&lt;input name="username" class="input" type="text" value="&lt;?php echo set_value('username'); ?&gt;" /&gt;&lt;/td>
    </tr>
    <tr>
        <td>Password: </td><td>&lt;input name="password" class="input" type="password" /&gt;
        </td>
        <td>&lt;?=form_submit('submit', 'Login');?&gt;</td>
    </tr>
</table>

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
&lt;?php
}else{
    echo 'Logged In';
    //redirect('theater', 'refresh');
}
?&gt;

----model----
Code:
function checkLogin()
    {
        $u1 = get_cookie('username');
        $p1 = get_cookie('password');

        $logged = $this->db->get_where('users', array ('username' => $u1, 'password' => $p1));

        //Rename some of the $logged['variables'] with easier names.
        $uId = $logged['id'];
        $uName = $logged['username'];
        
        if ($uName) {
            return $data['loggedIn'] = TRUE;
        }else{
            return $data['loggedIn'] = FALSE;
        }
    }

#2
[eluser]clip[/eluser]
Code:
&lt;?php
$loggedIn = $this->database->checkLogin();

if ($loggedIn == FALSE)
{
?&gt;
......

//or
if ($this->database->checkLogin() == FALSE)
{
?&gt;
......

Edit: Also your return should just be like this:

Code:
if ($uName) {
            return TRUE;
        }else{
            return FALSE;
        }

#3
[eluser]GamingFusion[/eluser]
$loggedIn is returned from the database model why do i have to make the function in the database model equal to it?

anyways that didnt help at all. it still doesnt work

#4
[eluser]BrianDHall[/eluser]
First, your $loggedIn will not be effected by your function because it returns a value that is simply discarded. Passing data though an array into a view happens when you call load->view() - you can't do it even by reference inside the view itself.

You'll need to have your checkLogin() function return true or false, and then do as Clip states above.

The next thing is you need to remove the if statements entirely and just see if your form displays sans login check. If it does, then you need to check the value of $loggedIn. If it is true then your form should display - if it doesn't then that's a clue what's the next thing that is wrong.

#5
[eluser]GamingFusion[/eluser]
I took out the if's in both the view and model and it didnt make a difference.

#6
[eluser]GamingFusion[/eluser]
There is something wrong with calling the checkLogin() function

#7
[eluser]BrianDHall[/eluser]
[quote author="GamingFusion" date="1257239539"]There is something wrong with calling the checkLogin() function[/quote]

I presume this means that when you take out that call in your view it loads fine?

Try using an otherwise empty function in your controller that just echos something directly, and make sure that loads ok. Then put in the call to check login, and see if that works.

Keep narrowing it down to see if you can find one specific line that causes the problem, then perhaps you'll have an answer or we can be of more help.

#8
[eluser]GamingFusion[/eluser]
it doesn't load this either

Code:
function echoSometing()
    {
        echo 'Something';    
    }

#9
[eluser]BrianDHall[/eluser]
Blank screen? Well then something has gone wrong way before all this then. Search the forums for "blank screen" or "white screen" - there is a whole set of things you'll need to check one by one to narrow down what happened.

You basically need to pair down your application, commenting out big pieces as you go, until you can get something that works properly. Or if you are just starting this application, just use a fresh install of CI and copy/paste, making sure it doesn't break as you go.

We can't troubleshoot code we don't have, so you'll need to work back to something that loads properly and then work your way back forward towards what you are wanting to do. I have found most whitescreens I experience are from models, but if that function is from a constructor and you don't even get a 404 then something else entirely is wrong.

#10
[eluser]GamingFusion[/eluser]
well in my other pages work just fine when loading a model but i will look into the search you told me to look at.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.