Login form problem

Discussion in 'PHP/MySql' started by pamelaluck, Jan 19, 2010.

Remove these ads by signing in
Remove these ads by signing in
Thread Status:
Not open for further replies.
  1. pamelaluck New Member

    Member Since:
    Jan 12, 2010
    Message Count:
    3
    Likes Received:
    1
    i have been trying to create a php login form..

    though i have failed. i need to know what is wrong and why it iis not working
    if correct user name and pass it will set a cookie.
    code is below :
    -----------------------
    <?php
    if (isset($_COOKIE['sugar']))
    {
    echo "welcome back!";
    die;
    }

    else {
    if (isset($_POST['submit']) && !empty($_POST['user']) && !empty($_POST['password'])) {

    if ($_POST['user'] = "user" && $_POST['password'] = "pass") {
    $cookie = setcookie("sugar", "sugar", time()+1000000000000, "/", "smarticals-and-cheese.site88.net", 0);
    setcookie("sugar", "sugar", time()+1000000000000, "/", "smarticals-and-cheese.site88.net", 0);

    if ($cookie === true) {
    echo "cookie was set no need to login again <br />";
    }

    else {
    echo "cookie was not set please enable cookies";
    }

    echo "login success";
    }
    else {
    echo "login failed";
    }
    }

    else {
    ?>
    <html>

    <body>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Username:<input type="text" name="user" />
    <br />
    Password: <input type="password" name="password" />
    <br />
    <input type="submit" name="submit" value="submit" />
    </form>
    </body>

    </html>
    <?php
    }
    }
    ?>


    though i already have a login form i just want to see why this won't work.
  2. Zoli New Member

    Member Since:
    Jan 23, 2007
    Message Count:
    563
    Likes Received:
    37
    Location:
    Hungary
    For first sight I think that the problematic part of the code is the $cookie comparison
    PHP:
    if ($cookie === true)
    . You should try somehow like this
    PHP:
    if(isset($_COOKIE["sugar"]))
  3. crivion Member

    Member Since:
    Nov 10, 2009
    Message Count:
    38
    Likes Received:
    0
    errr maybe
    if ($_POST['user'] == "user" && $_POST['password'] == "pass") {
Thread Status:
Not open for further replies.

Share This Page