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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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();
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

<?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');
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.