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 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    20
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Can't login after loggin out!!!!!

    Well, i don't know what is the problem in my code
    after creating an account ,am logged in and i can access my page
    but after logging out i can't log in again!!
    i don't know why??????
    PHP Code:
    <?php session_start();
    require 
    "forum.inc.php";
    $mainpage="<a href='main.php'>Proceed to the main page</a>";
    $logoutpage="<a href='welcomepage.php'>Logout</a>";

    if(
    $username && $password){
        if(
    $logged_in_user==$username){
            
    setup_page("Already logged in","Already logged in");
            echo 
    $username.",You are already logged in</br></br>";
            echo 
    $mainpage."</br>";
            echo 
    $logoutpage;
            exit();
        }
            
    $conn=mysqli_connect("localhost","root","","forum");
            
    $query=mysqli_query($conn,"select * from users where name='".$username."' 
                                        and password=password('"
    .$password."')");
            if(!
    $query)fail("database query faild",true);
            if(
    mysqli_num_rows($query)>0){            
                
    $record=mysqli_fetch_assoc($query);
                
    $logged_userID=$record["userID"];
                
    session_register("logged_userID");
                
    $logged_in_user=$username;
                
    session_register("logged_in_user");
                    if(
    $record["mod"]){
                        
    $logged_as_mod=true;
                        
    session_register("logged_as_mod");
                    }            
                    
    setup_page("Welcome","Welcome");
                    echo 
    $mainpage."</br>";
                    echo 
    $logoutpage;
                exit();
        }else{
            
    setup_page("login","Invalid login");
            echo 
    "Your username & password doesnt appear to match ,try again";
            }
        }
    elseif(
    $username || $password){
        
    setup_page("Invalid login","Invalid login");
        echo 
    "Please fill in both fields";

    }else{
        
    setup_page("login","login");
        echo 
    "Please entr your details to login";
    }
    ?>
    <form action="forumlogin.php" method="post">
    Username:
    <input type="text" name="username" maxlength="20" size="20">
    Password:
    <input type="password" name="password" maxlength="20" size="20">
    <input type="submit" value="Login">
    </form>
    <a href="forumregister.php">Register New User</a>

  • #2
    New Coder
    Join Date
    Oct 2007
    Posts
    20
    Thanks
    4
    Thanked 0 Times in 0 Posts
    it works only when i omit the password portion

    and password=password('".$password."')

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Where do you define $username and $password? If you don't define them and register_globals is on then it will come as a post variable however having register_globals on is a security risk. If you don't have them defined try change this
    PHP Code:
    require "forum.inc.php";
    $mainpage="<a href='main.php'>Proceed to the main page</a>";
    $logoutpage="<a href='welcomepage.php'>Logout</a>"
    to this
    PHP Code:
    require "forum.inc.php";
    $mainpage="<a href='main.php'>Proceed to the main page</a>";
    $logoutpage="<a href='welcomepage.php'>Logout</a>";
    $username$_POST['username'];
    $password$_POST['password']; 
    Now you may need to change your if statement because I believe the $_POST array always returns true so something like this instead
    PHP Code:
    if($username != '' && $password != ''){ 
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    New Coder
    Join Date
    Oct 2007
    Posts
    20
    Thanks
    4
    Thanked 0 Times in 0 Posts
    thnxxxx alot
    it worked
    my problem that i was putting the password in the database as char(12) and it was encodes and each time i register an account it gives the first 12 letter the same encoding values
    for example
    usernamene password=123456e
    username:two password=123456e
    so i changed it to char(50)
    to make it look like that
    usernamene password=123456eertubdf
    username:two password=123456eerertyu

    its all about database encoding


  •  

    Posting Permissions

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