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 5 of 5

Thread: Login Script??

  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Login Script??

    Hello,

    I need to build a simple login script, i have 3 accounts stored in a mysql data base, and i would like to maybe use cookies, but not sure if session would be better.

    could someone please show me an example of a login script that has these functions?

    thanks in advance for your time!

    -Ken

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ok, what if i were to just hardcode the username and password?
    could some one just show me the correct syntax?
    I know in ASP i was just able to use AND, but that doesn't seem to work here, and i haven't been able to find anything with google searches..

    PHP Code:
    <?php

    $user 
    $_POST['user'];
    $pass $_POST['pass'];

    if ( 
    $user == "admin" AND $pass == "admin" ) {

    header("Location: admin.php?edit");

    } else {

    header("Location: index.php?error=login");


    }


    ?>

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    AND should work, but I think it might be depreciated. Not sure though. Anyway, try using &&
    PHP Code:
    if($user == "admin" && $pass=="admin")( 

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yeah, weird, AND should work for you.
    Its not that its depreciated, it just has a lower precidence when it comes to comparing && and 'AND'. If you know your mathmatics well enough, program like your writting an equation, this will give you the same output.
    You should use some sessions though:
    PHP Code:
    <?php
    session_start
    ();

    if (empty(
    $_SESSION['username']))
    {
         if (
    $_POST['user'] == 'admin' AND $_POST['password'] == 'admin')
         {
              
    $_SESSION['username'] = $_POST['user']; // From this, should be admin.
              
    $_SESSION['password'] = $_POST['password'];
              
    header("location: admin.php?edit");
         }
         else
         {
              
    header("location: index.php?error=login");
         }
    }
    else
    {
         
    header("location: admin.php?edit");
    }
    ?>
    Or something of the sorts.

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ok, i'd like to use the session script,

    but how do I then check for the session on the pages after login?


    thanks again for all you help!
    -Ken


    ps: yah, && worked just fine:-)


  •  

    Posting Permissions

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