Looking for a very simple login for web page

Discussion in 'PHP' started by dougvcd, May 10, 2007.

  1. #1
    hi all
    i am a complete newbie to this php so bear with me
    have done searches for login and they all seem very complicated to work out
    all i want is a simple login php
    that just checks username and pass word from my database not to worried at the moment about encryption and that till i learn more
    i have database set up and registration set up just need login check
    many thanks
    Doug
     
    dougvcd, May 10, 2007 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Consider doing it via htaccess. Much easier.
     
    T0PS3O, May 10, 2007 IP
  3. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for the reply
    but havnt got a clue about what you suggest
    like i said total newbie
    cheers
    Doug
     
    dougvcd, May 10, 2007 IP
  4. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    T0PS3O, May 10, 2007 IP
  5. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks again for that
    what it is for is on my web site i have 2 choices free view page and a member page
    and reg page so that peeps can reg them selves then view members page
    with out me having to do any thing
    if you understand what i mean
    if you want to have a look
    addy is
    www.caravan-holiday-exchange.com
    you can see members page at moment thats why i need the login
    cheers
    Doug
     
    dougvcd, May 10, 2007 IP
  6. Chris.

    Chris. Guest

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Here is the login check script that I use. You will have to edit it, but it shouldn't be that hard.

    You might have to change the config.php file to your database connection file.
    
    <?php
    
    include("config.php");
    
    $username = $_SESSION['username'];
    
    if (!isset($_SESSION['logged_in']))
    {
    	if (!isset($_POST['check_login']))
    	{
    		echo"
    		<table width='300' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>
    			<tr>
    				<form name='form' action='login.php' method='POST'>
    				<td>
    			<table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#FFFFFF'>
    			<tr>
    				<td colspan='3'><strong>Member Login </strong></td>
    			</tr>
    			<tr>
    				<td width='78'>Username</td>
    				<td width='6'>:</td>
    				<td width='294'><input name='username' type='text' /></td>
    			</tr>
    			<tr>
    				<td>Password</td>
    				<td>:</td>
    				<td><input name='password' type='password' /></td>
    			</tr>
    			<tr>
    				<td><a href='register.php?action=new'>New User</a></td>
    				<td>&nbsp;</td>
    				<td><input type='submit' name='check_login' value='Log In' /></td>
    			</tr>
    			</table>
    				</td>
    				</form>
    			</tr>
    		</table>";
    	}
    	elseif (isset($_POST['check_login']))
    	{
    		$username = $_POST['username']);
    		$password = md5($_POST['password']);
    		
    		if (empty($password) || empty($username))
    		{
    			echo"You left a field blank!";
    		}
    		else
    		{
    			$check_login_query = "SELECT `username`, `password`, `id` FROM `members` WHERE `username` = '$username' AND password = '$password' LIMIT 1";
    			$check_login = mysql_query($check_login_query);
    			
    			if (mysql_num_rows($check_login) > 0) 
    			{
    				$_SESSION['logged_in'] = 1;
    				$_SESSION['username']  = $username;
    				
    				echo"You have successfully logged in! You will be redirected in three seconds!><br /><br />
    				
    				<div class='info'>If you don't wish to wait, <a href='index.php'>click here</a>";
    				
    				echo'<meta http-equiv="REFRESH" content="3;url=index.php">';
    			}
    			else
    			{
    				echo"You have supplied an invalid username and/or password!";
    			}
    		}
    	}
    }
    ?>
    
    Code (markup):
     
    Chris., May 10, 2007 IP
  7. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks chris for that but i couldnt get it to run came up with errors
    cheers any way
    Doug
     
    dougvcd, May 11, 2007 IP
  8. Chris.

    Chris. Guest

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    What errors, probably a mysql error, correct?
     
    Chris., May 11, 2007 IP
  9. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    thanks to all for the help
    but it is to hard for understand at my age so have given up for now
    thanks
    Doug
     
    dougvcd, May 12, 2007 IP
  10. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #10
    you can make simple login system using Cookie.it is not that secure,but you can use it.just post the username and password in a page,check if it and if it ok then set the cookie with any value.
    example setcookie('logged','yes',time()+14*60*60);

    now in the pages where u want check if the user is logged in or not then you can just check if the 'logged' Cookie's value is 'yes'.if it is 'yes' then ok otherwise you can redirect them to login page.

    i hope it will help you:D

    coderbari's homepage
     
    coderbari, May 14, 2007 IP
  11. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    thanks for that
    but not what i need
    need some thing a little better but simple
    cheers
    Doug
     
    dougvcd, May 15, 2007 IP
  12. iatbm

    iatbm Prominent Member

    Messages:
    5,151
    Likes Received:
    352
    Best Answers:
    0
    Trophy Points:
    360
  13. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #13
    legend2, May 18, 2007 IP
  14. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #14
    thanks to all for info
    cheers
    Doug
     
    dougvcd, May 18, 2007 IP