Jump to content

Help displaying a particular page on first login


lukep11a

Recommended Posts

Hi I have the following code to check the user login information, how would I insert code that checks the column 'username' from the table 'selections' for the username entered on login and if it doesn't exist then member-home.php is displayed, and if it does exist then teamselections.php is displayed?

 

<?php
function checkLogin($u, $p)
{
global $seed; // global because $seed is declared in the header.php file

    if (!valid_username($u) || !valid_password($p) || !user_exists($u))
    {
        return false; // the name was not valid, or the password, or the username did not exist
    }

    //Now let us look for the user in the database.
    $query = sprintf("
	SELECT loginid 
	FROM login 
	WHERE 
	username = '%s' AND password = '%s' 
	AND disabled = 0 AND activated = 1 
	LIMIT 1;", mysql_real_escape_string($u), mysql_real_escape_string(sha1($p . $seed)));
    $result = mysql_query($query);
    // If the database returns a 0 as result we know the login information is incorrect.
    // If the database returns a 1 as result we know  the login was correct and we proceed.
    // If the database returns a result > 1 there are multple users
    // with the same username and password, so the login will fail.

    if (mysql_num_rows($result) != 1)
    {
        return false;
    } else
    {
        // Login was successfull
        $row = mysql_fetch_array($result);
        // Save the user ID for use later
        $_SESSION['loginid'] = $row['loginid'];
        // Save the username for use later
        $_SESSION['username'] = $u;
        // Now we show the userbox
        return true;
    }
    return false;
}

?>

 

Any help would be much appreciated.

 

Thanks

Luke

Hi I have the following code to check the user login information, how would I insert code that checks the column 'username' from the table 'selections' for the username entered on login and if it doesn't exist then member-home.php is displayed, and if it does exist then teamselections.php is displayed?

 

something like:

"select * from `selections` where `username` = '$username' limit 1"

 

hope this helps

I can't get it to work, I don't know if I'm putting the code in the wrong place, I also have the following code in login.php that links to the previous code, should it placed somewhere within this instead?

 

<?php
if (!isLoggedIn())
{
    // user is not logged in.
    if (isset($_POST['cmdlogin']))
    {
        // retrieve the username and password sent from login form & check the login.
        if (checkLogin($_POST['username'], $_POST['password']))
        {
            show_userbox();
        } else
        {
            echo "Incorrect Login information !";
            show_loginform();
        }
    } else
    {
        // User is not logged in and has not pressed the login button
        // so we show him the loginform
        show_loginform();
    }

} else
{
    // The user is already loggedin, so we show the userbox.
    show_userbox();
}
?>

I don't think I am explaining myself properly. I have two tables one called 'members' with all the users details in and one called 'selections' where each user is required to make a few selections on their first login. So basically I am asking how I can apply code on login to check to see if the user that has logged in has already made their selections by checking to see if they already exist in the username column of the 'selections' table, and if they do take them to the member homepage 'member-home.php' and if not to the selections page 'teamselections.php'.

 

I hope that makes sense. Thanks in advance.

I have tried applying the code given but so far still can't it to work, are there any other ways it can be done that i can try? or is there a particular place within my code that it needs to be put? I tried placing it at the end of the login.functions.php which is the first set of code? Any help would be greatly appreciated!

<?php
if (!isLoggedIn())
{
    // user is not logged in.
    if (isset($_POST['cmdlogin']))
    {
        // retrieve the username and password sent from login form & check the login.
        if (checkLogin($_POST['username'], $_POST['password']))
        {
            show_userbox();
        } else
        {
            echo "Incorrect Login information !";
            show_loginform();
        }
    } else
    {
        // User is not logged in and has not pressed the login button
        // so we show him the loginform
        show_loginform();
    }

} else
{
    // The user is already loggedin, so we show the userbox.
    show_userbox();
}

"select * from `selections` where `username` = '$username' limit 1"
if (checkLogin($user, $pass))
{
header('Location: member-home.php');
}
else
{
header('Location: teamselections.php');
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.