login problem

Discussion in 'PHP' started by Joskevic, Jun 24, 2006.

  1. #1
    Hi

    I already managed to create some login code, but what I was trying was to set up an individual login, so that a different user gets a different site after login.

    This is the code I already use:

    login.php:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <style>
    label 
    {
    width:25%; text-align:left; float:left; font-weight:bold;
    }
    .row
    {
    padding: 5px;
    }
    </style>
    <body>
    
    <form action="logincheck.php" method="post">
    <div class="row"><label for="name">Login: </label><input type="text" name="login" size="15"></div>
    <div class="row"><label for="password">Password: </label><input type="password" name="password" size="15"></div>
    <div class="row"><input type="submit" value="Log in"></div>
    </form>
    
    
    </body>
    </html>
    
    Code (markup):
    logincheck.php
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <?php
    $login=$_POST['login'];
    $password=$_POST['password'];
    $found=false;
    
    $con = mysql_connect('localhost','login','pass');
    mysql_select_db('vcdozies', $con);
    $query = 'SELECT * FROM login WHERE login=addslashes($login)';
    $result = mysql_query($query);
    $row=$result;
    $goal=''.$result['goal'];
    if (strcmp($row['password'],$password)) 
    	{
    	echo (addslashes($goal));
    	if(strcmp($row['login'],$login)) {echo ('<meta http-equiv="refresh" content="5;url='.addslashes($goal).'">');$found=true;}
    	}
    echo ('
    </head>
    
    <body>');
    if (!$found) {echo ('Invalid pass/username');}
    mysql_close($con);
    echo('</body>
    </html>');
    ?>
    Code (markup):
    My MySQL db table login is a table with 4 fields (id,login,password and goal). But when I load the page ( http://vcdozies.phpnet.us/test/login.php
    and I give in the username (=laurens) - pass (=persoons) I get the refresh page, but in the refresh meta tag is no url filled in.
    What am I doing wrong?
     
    Joskevic, Jun 24, 2006 IP
  2. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #2
    vishwaa, Jun 24, 2006 IP
  3. dtang4

    dtang4 Active Member

    Messages:
    303
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #3
    If you don't output the header information just yet, once you verify the login, you can use a Header redirect.
     
    dtang4, Jun 24, 2006 IP
  4. Joskevic

    Joskevic Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I do understand my code is still primitive, but I think it's quite correct except the redirect function. And that link you gave, there's nothing in it of a custom redirect. I mean when I sign in, I get page x.php, when someone else signs in, he/she gets page y.php. That's what my goal is for this little project.

    Ty
     
    Joskevic, Jun 25, 2006 IP