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 help

  1. #1
    L__
    L__ is offline
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Login help

    Hey everyone,
    I have had trouble with my login system. the problem is the page keeps refreshing. Here is the code.
    Code:
    <?php
    
    
    if (ISSET($_POST['sublogin']))
    {
    // Recreation of variables for later encryption uses the $_POST  will be replaced with the decrypted source
    $username = trim($_POST['username']);
    $password =  trim($_POST['password']);
    $cryptpassword = md5($password);
    $url = '/cp.php?user=$_SESSION[username]';
    //Connects to DB
    require("database.php");
    $table = "users";
    
    $sql="SELECT username, userID FROM $table WHERE username='$username' and password='$cryptpassword'";
    $result = mysql_query($sql)or die(mysql_error());
    
    // If result matched $myusername and $mypassword, table row must be 1 row
    if(mysql_num_rows($result) > 0)
    	{
    // Registers sesions and redirect to file "login_success.php"
    
    $storage = mysql_fetch_assoc($result);
    
    	//Sessions here
       $_SESSION['username'] = $storage['username'];
       $_SESSION['userid'] = $storage['userID'];
       
    	header("location: $url");
    	}
    else 	
    	{
    	echo "Wrong Username or Password";
    	}
    }
       
    function displayLogin(){
       global $logged_in;
       if($logged_in){
        echo "Logged In<br />";
       echo "Welcome <b>$_SESSION[username]</b>, you are logged in. <br><br>"
           ."<a href=\"cp.php?user=$_SESSION[username]\">My Account</a><br />   ";
           echo "<a href=\"logout.php\">Logout</a>";
       }
       else{
    ?>
    
    <form action="" method="post">
    <table align="left" border="0" cellspacing="0" cellpadding="3">
    <tr><td>Username:</td></tr><tr><td><input type="text" name="username" size="15" maxlength="30"/></td></tr>
    <tr><td>Password:</td></tr><tr><td><input type="password" name="password" size="15" maxlength="30"></td></tr><tr><td>
    <input type="submit" name="sublogin" value="Login" style="font-size: 8pt; color: #000000; word-spacing: 0; margin-top: 0; margin-bottom: 0" /></td></tr>
    </table>
    </form>
    <?PHP
     }
    }
    
    
    
       /**
        * This is the cool part: the user has requested that we remember that
        * he's logged in, so we set two cookies. One to hold his username,
        * and one to hold his md5 encrypted password. We set them both to
        * expire in 100 days. Now, next time he comes to our site, we will
        * log him in automatically.
        */
       if(isset($_POST['remember'])){
          setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/");
          setcookie("cookid", $_SESSION['userid'], time()+60*60*24*100, "/");
       }
    
       /* Quick self-redirect to avoid resending data on refresh */
       echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
       return;
    
    
    /* Sets the value of the logged_in variable, which can be used in your code */
    $logged_in = checkLogin();
    
    
    
    ?>
    The website is at both, infinitevortex.ulmb.com/login.php and taizkul.prohosts.org. They ue the same script...but i made two for testing purposes
    Thank you for your time
    ~L

  • #2
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts

    Well.....

    I'm just taking a shot in the dark... But I think you might want to try starting your session at the very top of you page.


  •  

    Posting Permissions

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