Closed Thread
Page 5 of 8 FirstFirst ... 34567 ... LastLast
Results 41 to 50 of 77

Thread: Simple Register-Login-Logoff System

  1. #41
    Join Date
    Sep 2008
    Posts
    20
    Rep Power
    0

    Re: Simple Register-Login-Logoff System

    its helpful for beginners

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #42
    r.o.b.e.r.t is offline Newbie
    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Re: Simple Register-Login-Logoff System

    thanks

  4. #43
    tecktalk is offline Programmer
    Join Date
    May 2008
    Posts
    179
    Rep Power
    0

    Re: Simple Register-Login-Logoff System

    Hmm not sure about what is helpful and what is not But it is surely a good code which is really simple.. yes It can be done easily in Html but Dude if you are mixing both php and html then its gonna make it mixed!!! mind it..
    ____________________
    Missouri Sexual Predators Online Adult Games

  5. #44
    booher is offline Newbie
    Join Date
    Dec 2008
    Posts
    1
    Rep Power
    0

    Re: Simple Register-Login-Logoff System

    Quote Originally Posted by Jaan View Post
    First make a database and upload those tables into your database:

    users.sql

    [HIGHLIGHT="SQL"]CREATE TABLE `users` (
    `id` INT( 50 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `username` VARCHAR( 15 ) NOT NULL ,
    `password` VARCHAR( 15 ) NOT NULL ,
    `email` VARCHAR( 50 ) NOT NULL
    )[/HIGHLIGHT]

    index.php

    Code:
    <?php

    //This will start a session
    session_start();

    $username $_SESSION['username'];
    $password $_SESSION['password'];

    //Check do we have username and password
    if(!$username && !$password){
    echo 
    "Welcome Guest! <br> <a href=login.php>Login</a> | <a href=register.php>Register</a>";
    }else{
    echo 
    "Welcome ".$username." (<a href=logout.php>Logout</a>)";
    }


    ?>
    Now let's make a register.php file

    Code:
    <?php

    //This function will display the registration form
    function register_form(){

    $date date('D, M, Y');
    echo 
    "<form action='?act=register' method='post'>"
        
    ."Username: <input type='text' name='username' size='30'><br>"
        
    ."Password: <input type='password' name='password' size='30'><br>"
        
    ."Confirm your password: <input type='password' name='password_conf' size='30'><br>"
        
    ."Email: <input type='text' name='email' size='30'><br>"
        
    ."<input type='hidden' name='date' value='$date'>"
        
    ."<input type='submit' value='Register'>"
        
    ."</form>";

    }

    //This function will register users data
    function register(){

    //Connecting to database
    $connect mysql_connect("host""username""password");
    if(!
    $connect){
    die(
    mysql_error());
    }

    //Selecting database
    $select_db mysql_select_db("database"$connect);
    if(!
    $select_db){
    die(
    mysql_error());
    }

    //Collecting info
    $username $_REQUEST['username'];
    $password $_REQUEST['password'];
    $pass_conf $_REQUEST['password_conf'];
    $email $_REQUEST['email'];
    $date $_REQUEST['date'];

    //Here we will check do we have all inputs filled

    if(empty($username)){
    die(
    "Please enter your username!<br>");
    }

    if(empty(
    $password)){
    die(
    "Please enter your password!<br>");
    }

    if(empty(
    $pass_conf)){
    die(
    "Please confirm your password!<br>");
    }

    if(empty(
    $email)){
    die(
    "Please enter your email!");
    }

    //Let's check if this username is already in use

    $user_check mysql_query("SELECT username FROM users WHERE username='$username'");
    $do_user_check mysql_num_rows($user_check);

    //Now if email is already in use

    $email_check mysql_query("SELECT email FROM users WHERE email='$email'");
    $do_email_check mysql_num_rows($email_check);

    //Now display errors

    if($do_user_check 0){
    die(
    "Username is already in use!<br>");
    }

    if(
    $do_email_check 0){
    die(
    "Email is already in use!");
    }

    //Now let's check does passwords match

    if($password != $pass_conf){
    die(
    "Passwords don't match!");
    }


    //If everything is okay let's register this user

    $insert mysql_query("INSERT INTO users (username, password, email) VALUES ('$username', '$password', '$email')");
    if(!
    $insert){
    die(
    "There's little problem: ".mysql_error());
    }

    echo 
    $username.", you are now registered. Thank you!<br><a href=login.php>Login</a> | <a href=index.php>Index</a>";

    }

    switch(
    $act){

    default;
    register_form();
    break;

    case 
    "register";
    register();
    break;

    }

    ?>
    Now let's make a login page, login.php:

    Code:
    <?php
    session_start
    ();

    //This displays your login form
    function index(){

    echo 
    "<form action='?act=login' method='post'>" 
        
    ."Username: <input type='text' name='username' size='30'><br>"
        
    ."Password: <input type='password' name='password' size='30'><br>"
        
    ."<input type='submit' value='Login'>"
        
    ."</form>";    

    }

    //This function will find and checks if your data is correct
    function login(){

    //Collect your info from login form
    $username $_REQUEST['username'];
    $password $_REQUEST['password'];


    //Connecting to database
    $connect mysql_connect("host""username""password");
    if(!
    $connect){
    die(
    mysql_error());
    }

    //Selecting database
    $select_db mysql_select_db("database"$connect);
    if(!
    $select_db){
    die(
    mysql_error());
    }

    //Find if entered data is correct

    $result mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
    $row mysql_fetch_array($result);
    $id $row['id'];

    $select_user mysql_query("SELECT * FROM users WHERE id='$id'");
    $row2 mysql_fetch_array($select_user);
    $user $row2['username'];

    if(
    $username != $user){
    die(
    "Username is wrong!");
    }


    $pass_check mysql_query("SELECT * FROM users WHERE username='$username' AND id='$id'");
    $row3 mysql_fetch_array($pass_check);
    $email $row3['email'];
    $select_pass mysql_query("SELECT * FROM users WHERE username='$username' AND id='$id' AND email='$email'");
    $row4 mysql_fetch_array($select_pass);
    $real_password $row4['password'];

    if(
    $password != $real_password){
    die(
    "Your password is wrong!");
    }



    //Now if everything is correct let's finish his/her/its login

    session_register("username"$username);
    session_register("password"$password);

    echo 
    "Welcome, ".$username." please continue on our <a href=index.php>Index</a>";




    }

    switch(
    $act){

    default;
    index();
    break;

    case 
    "login";
    login();
    break;

    }
    ?>
    And now.. logout.php

    Code:
    <?php
    session_start
    ();

    //This function will destroy your session
    session_destroy();
    echo 
    "You are now logged out! <a href=index.php>Index</a> or <a href=login.php>Login</a>";

    ?>
    I hope it helped.. have fun!
    Looks good

  6. #45
    Will_00 is offline Newbie
    Join Date
    Mar 2008
    Posts
    1
    Rep Power
    0

    Re: Simple Register-Login-Logoff System

    Nice..

  7. #46
    Jaan Guest

    Re: Simple Register-Login-Logoff System

    thanks dude
    Posted via CodeCall Mobile

  8. #47
    tamir is offline Newbie
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Re: Simple Register-Login-Logoff System

    When I complete to login or register i press the button and he doing nothing.
    What I need to do?

  9. #48
    Jaan Guest

    Re: Simple Register-Login-Logoff System

    Hmm.. I have seen many guys who have this problem but I really don't know what's causing it because I have tested it on Linux and on Windows platforms and on both they work.. So I don't know how to help you, sorry

  10. #49
    betty02 is offline Newbie
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Re: Simple Register-Login-Logoff System

    Cheers will try this now!

  11. #50
    ko7et2000 is offline Newbie
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Re: Simple Register-Login-Logoff System

    thx dude

Closed Thread
Page 5 of 8 FirstFirst ... 34567 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Similar Threads

  1. Login and Register Forms, using database
    By Zvone in forum Visual Basic Programming
    Replies: 2
    Last Post: 09-03-2011, 11:17 AM
  2. Simple Login/Register/Main Script
    By Whitey in forum PHP Tutorials
    Replies: 40
    Last Post: 09-27-2010, 12:25 AM
  3. Login Script - With MySql - Register
    By jthom263 in forum PHP Development
    Replies: 1
    Last Post: 05-08-2010, 04:10 AM
  4. Login/Register Script
    By Whitey in forum PHP Development
    Replies: 6
    Last Post: 06-07-2008, 10:34 AM

Bookmarks

Posting Permissions

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