Jump to content

Redirect upon login


lukep11a

Recommended Posts

Hi, I wonder if anyone can help me. I am running a fantasy football league, when a user logs in I want them to be directed to teamselections.php which is where they make their team selections, once they click submit their choices have been set and they will not need to do it again. So I thought at this point I could update the column 'firstlogin' in my 'login' table with a '1'.

 

So technically, it may not be just the first time they login (if for example they do not submit their team selections right away, or their pc crashes etc.), but until they have submitted their team selections 'firstlogin' value will be '0' so they will be directed to teamselections.php. Once they have submitted them 'firstlogin' value will be '1' and they will be directed to myaccount.php.

 

Hope that makes sense. So, what I am asking is how do I apply that to the code I already have. Sorry I am still relatively new to php! I would be so grateful if anyone can help me I have been tearing my hair out over this for days.

 

These are my login functions:

<?php

#### Login Functions #####


function isLoggedIn()
{

    if (session_is_registered('userid') && session_is_registered('email'))
    {
        return true; // the user is loged in
    } else
    {
        return false; // not logged in
    }

    return false;

}

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

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

    //Now let us look for the user in the database.
    $query = sprintf("
	SELECT userid 
	FROM login 
	WHERE 
	email = '%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 email 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['userid'] = $row['userid'];
        // Save the email for use later
        $_SESSION['email'] = $u;
        // Now we show the userbox
        return true;
    }
    return false;
}


?>

 

This is my login script:

<?php
if (!isLoggedIn())
{
    // user is not logged in.
    if (isset($_POST['cmdlogin']))
    {
        // retrieve the email and password sent from login form & check the login.
        if (checkLogin($_POST['email'], $_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 apologise for their being so much to read, I hope somebody can help.

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.