Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Login Script

  1. #1
    New Coder
    Join Date
    Sep 2008
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Login Script

    I have a login script. However i need some help with if there is a user logged in the script will redirect him rather than have them login again.

    PHP Code:
    <?
    session_start
    ();
    header("Cache-control: private");
    include 
    'includes/db_connect.php';

    if (!
    $_SESSION['username'] || !$_SESSION['email']){
    $username $_POST['username'];
    $password $_POST['password'];
    $username strip_tags($username);
    $password strip_tags($password);
    $ip $REMOTE_ADDR;
    $domain $_SERVER['REMOTE_ADDR'];

    $username=strtolower($username);

    if((!
    $username) || (!$password)){
        echo 
    "<br>You have not submitted one or more fields <br/>";
    }else{

    ///check INFO
    $sql mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1' LIMIT 1");
    $login_check mysql_num_rows($sql);


    ///other
    if ($login_check == '1'){
            
    ini_set(session.cookie_lifetime"3600");
            
    session_register('username');
            
    $_SESSION['username'] = $username;
            
    session_register('email_address');
            
    $_SESSION['email_address'] = $email_address;
             
    $timestamp time();
    $timeout $timestamp-$timeoutseconds;
    $cool gmdate('Y-m-d h:i:s');
    mysql_query("UPDATE users SET lastlogin='$cool' WHERE username='$username'");
    mysql_query("UPDATE users SET online='$timestamp' WHERE username='$username'");

    mysql_query("UPDATE users SET ip='$domain' WHERE username='$username'");

    echo 
    "<meta http-equiv='Refresh' content=0;url=logged.php>
    "
    ;

    } else {
        echo 
    "wrong username/password combination or account not yet activated
        "
    ;
        include 
    'login.php';
    }}}
    ?>
    any help would be appreciated.

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    create a verify_auth() function returning Boolean. basicaly to check whether a) the session is created and b) whether the session details are valid. then you can bypass the login.

    PHP Code:
    if( ! verify_auth() ){
        
    //...do login script

    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •