Results 1 to 6 of 6

simple php login form

This is a discussion on simple php login form within the Coding Help forums, part of the Webmaster Discussion category; where would u go for a simple login form tutorial...

  1. #1
    Coder
    Join Date
    Apr 2007
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default simple php login form

    where would u go for a simple login form tutorial

  2. #2
    respect my AW-THOR-IT-AYY Forbairt's Avatar
    Join Date
    Jun 2007
    Location
    My Office, Dublin
    Posts
    2,421
    Thanks
    6
    Thanked 16 Times in 15 Posts

    Default

    personally I wouldn't mind going to cuba for one .. but I'm not sure they'd have one there


    How simple do you want ?

    Does it pull from a database or it it simply to hide some in page info ...

    Could you use .htaccess for the pages which might be simpler

  3. #3
    Coder
    Join Date
    Apr 2007
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Forbairt View Post
    personally I wouldn't mind going to cuba for one .. but I'm not sure they'd have one there


    How simple do you want ?

    Does it pull from a database or it it simply to hide some in page info ...

    Could you use .htaccess for the pages which might be simpler
    want to login to a system and probably redirect to a page would pull a username and password

  4. #4
    respect my AW-THOR-IT-AYY Forbairt's Avatar
    Join Date
    Jun 2007
    Location
    My Office, Dublin
    Posts
    2,421
    Thanks
    6
    Thanked 16 Times in 15 Posts

    Default

    Quote Originally Posted by Keewee6 View Post
    want to login to a system and probably redirect to a page would pull a username and password
    How to Build a Full-Featured Login System: New PLUS Tutorial - Nettuts+ would probably be good to get you up to speed on it all

  5. #5
    Wannabe Geek php.allstar's Avatar
    Join Date
    Apr 2009
    Location
    Monamolin, Gorey, Co. Wexford
    Posts
    400
    Thanks
    4
    Thanked 13 Times in 12 Posts

    Thumbs up Simple PHP login form tutorial

    Hi,

    In my opinion, you should go right here for a login form tutorial!

    <?php

    // Use this at the top of every page you want to retain the user's login state
    session_start();

    // This function returns true (and stores some info in the session) if we have a valid user and returns false if not.
    function validUser($username,$password)
    {

    // Connect to your database (replace hostname, username, password, dbname with your own database details)
    mysql_connect('hostname','username','password') or die ('Can\'t connect to database server');
    mysql_select_db('dbname') or die ('Can\'t use database');

    // Escape nasty characters to preven sql injection (never trust user input)
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string($password);

    // You will have had to set up a user table in the database
    // Change the table, Username and Password to suit your database structure
    $query = "SELECT COUNT(*) AS count FROM table WHERE Username='" . $username . "' AND Password='" . $password . "'";
    $result = mysql_query($query);

    // If we have found one row, the user is a valid user
    if(mysql_num_rows($result) == 1){

    // Store some data in the session for use later if you want
    $_SESSION['loggedIn'] = 1;
    $_SESSION['username'] = $username;

    return TRUE;

    // If there are zero or more than 1 rows the user is not a valid user.
    // You will have to prevent the same user creating multiple accounts with the same details in your registration form code
    } else {

    return FALSE;

    }

    }

    // If the login form was submitted...
    if(isset($_POST['login'])){

    // If we don't have a valid user, display an error message
    if(!validUser($_POST['username'],$_POST['password'])){

    echo '<p>You did not provide valid login details</p>';

    // If we do have a valid user, display a welcome message
    } else {

    echo '<p>Thanks, you are now looged in!</p>';

    }

    }

    ?>

    <form name="login" method="post" action="">
    <p><label>Username:</label><input type="text" name="username" id="username" /></p>
    <p><label>Password:</label><input type="text" name="password" id="password" /></p>
    <p><input type="hidden" name="login" value="1" /><input type="submit" value="Login" /></p>
    </form>

    Copy all that code above into your code editor so you can read it easier with syntax highlighting, I still haven't figured out how to display php code with syntax highlighting in this forum!

    Make sure you use session_start(); at the top of all pages where you want to check for logged in users with a bit of extra code...

    <?php

    session_start();

    if($_SESSION['loggedIn'] != 1){

    echo 'You must be logged in to view this page';
    exit();

    }

    ?>

  6. #6
    Coder
    Join Date
    Oct 2008
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default


Similar Threads

  1. Login box
    By gingem in forum Forum Feedback, Development and Competitions
    Replies: 0
    Last Post: 07-02-2009, 03:06 PM
  2. php login session
    By conor in forum Coding Help
    Replies: 1
    Last Post: 09-01-2009, 04:42 AM

Visitors found this page by searching for:

simple login form php

simple login form in php

php simple login form

login form php

simple php login form

php login formsimple php loginlogin form in phpform login phpphp simple loginphp login formssimple php login code archivelogin form php codephp login form simpleform php loginphp login simplephp login codesimple login code in phpsimple login phpsimple login formphp loginshare form php loginphp login delicioussimple php login -mysqlsimple php login code

Tags for this Thread

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79