[TUTORIAL] Creating a login script for multiple users.

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • nbop
    Corporal

    • Jun 2006
    • 10

    [TUTORIAL] Creating a login script for multiple users.

    Have you ever wanted to make a login script so you can have membercontent?
    This tutorial will show you how using php. No database will be used.

    1) Creating a form
    Here is the code for making the form. The form asks for your username and password. Save this code as login.php

    Code:
    <html>
    <head>
    <title>Please login</title>
    </head>
    <body>
    <?php
    if(isset($_GET["wrong"])){
    echo("<b>Username or password is incorrect!<br />Please try again.</b>");
    }
    ?>
    
    <form action="login2.php" method="post">
    <br />
    Username:<br />
    <input type="text" name="username" /><br />
    Password:<br />
    <input type="password" name="password" />
    <br />
    <br />
    <input type="submit" value="Login" />
    </form>
    
    </body>
    </html>
    The piece of php code will tell the viewer that he or she typed a wrong username or password.
    between the <form></form> tags we have 3 input fields. 1 for the username, 1 for the password, and 1 that will submit the inputs and send it to login2.php.
    Note that the form will be sent using the "post" method. This is the safest.

    2)Checking the userinput
    In this step we will check if the username and password are correct.
    This is done with php. No html will be used.
    Create a new page and call it login2.php. Give it the following content:
    PHP Code:
    <?php
    $usernames 
    = array("user1""user2""user3""superman");
    $passwords = array("pass1""pass2""password3""supermans password");
    $page "mypage.php";



    for(
    $i=0;$i<count($usernames);$i++){
      
    $logindata[$usernames[$i]]=$passwords[$i];
    }
    if(
    $logindata[$_POST["username"]]==$_POST["password"]){
    session_start();
    $_SESSION["username"]=$_POST["username"];
    header('Location: '.$page);
    exit;
    }else{
    header('Location: login.php?wrong=1');
    exit;
    }
    ?>
    You might want to edit the first 3 lines.
    1)$usernames is an array with all the usernames. To add a new one:
    PHP Code:
    $usernames = array("user1""user2""user3""superman""new one"); 
    2)$passwords is an array with all the passwords. To add a new one:
    PHP Code:
    $passwords = array("pass1""pass2""password3""supermans password""new one"); 
    Make sure that the username and the password have the same position.
    user1 will be able to login with the password pass1, not with any other password. user2 with pass2 and no other.
    3)$page is the page the user will go to when he is logged in. Change mypage.php to the page you would like to be the main page for logged in users. make sure the quotationmarks are still around it!

    3) Checking if the user is still logged in
    Create a new page, call it login3.php with the following code:
    PHP Code:
    <?php
    session_start
    ();
    if(!isset(
    $_SESSION["username"]){
    header('Location: login.php');
    exit;
    }
    ?>
    This code simply checks if the sesion that we made in login2.php has a value.
    If it doesn't it sends you to the login page.

    4) Making your pages protected
    All the pages that you want to be protected need to have a .php extension! otherwise they cannot be protected. Add this piece of code to the first line.
    PHP Code:
    <?php require("login3.php"); ?>
    Make sure it is on the first line. Otherwise it will give you an error.
    Now you pages are protected! simple?


    5) Extras
    making a log out page:
    make a new .php page and add the following contents at the very beginning:
    PHP Code:
    <?php session_start();session_unset();session_destroy(); ?>

    Your fancy logout message here
    create a link somewhere on your secured pages that leads to the logout page and the user will be logged out when he clicks the link.

    An other extra: showing the user's name: just put this piece of code in any secured page where you want to show the name:
    PHP Code:
    <?php echo($_SESSION["username"]); ?>
  • Watdaflip
    Major General

    • Sep 2005
    • 2116

    #2
    Re: [TUTORIAL] Creating a login script for multiple users.

    Just keep in mind not to intergate this with your website using BV, because its impossible with BV to put php in before the head is declared. This is going to give you an error when using session_start();

    session_start(); has to be declared on the first line of a page (or second if you count <?php) before any other header is declared

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

    Comment

    • nbop
      Corporal

      • Jun 2006
      • 10

      #3
      Re: [TUTORIAL] Creating a login script for multiple users.

      If you are using BV just create your page, save it nad then open it with notepad or an other plain text editor. Now you can add the php code.

      Comment

      • vedprakash
        Private First Class

        • Jun 2006
        • 9

        #4
        Re: [TUTORIAL] Creating a login script for multiple users.

        Originally posted by nbop
        If you are using BV just create your page, save it nad then open it with notepad or an other plain text editor. Now you can add the php code.
        sir,
        will you please tell me how can l use the above script if I am using blue
        voda.
        How to save the pages as .php extension

        Comment

        • Pablo
          Moderator

          • May 2005
          • 507

          #5
          Re: [TUTORIAL] Creating a login script for multiple users.

          Just keep in mind not to intergate this with your website using BV
          Yes, you can insert this code directly into BV:
          View->Page HTML->Start of Page
          Forum Moderator
          BlueVoda Spe******t

          Comment

          • navaldesign
            General & Forum Moderator

            • Oct 2005
            • 12080

            #6
            Re: [TUTORIAL] Creating a login script for multiple users.

            Only one observation: the usernames and passwords in this script are hardcoded in the script itself. This means that the script - login2.php - needs to be edited manually everytime a new user must be added. This is not so convenient, if you expect to have many visitors. There will also be a "dead" time before the site administrator updated the script.

            A solution would be (of course) to use a database, or, have the registration form info (username and password) writen in an file, which could be in this way automatically updated, as this BlueVoda Login script does here: > BV’s new built in Login system – a brief tutorial.


            However, very useful!. Well done mate!
            Navaldesign
            Logger Lite: Low Cost, Customizable, multifeatured Login script
            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

            Comment

            • vedprakash
              Private First Class

              • Jun 2006
              • 9

              #7
              Re: [TUTORIAL] Creating a login script for multiple users.

              I have got the downlodable pages from form maker now where to upload these pages and how to upload.

              should it be upload thru publishing blue voda or
              blue ftp or cpanel file manager.

              Comment

              • navaldesign
                General & Forum Moderator

                • Oct 2005
                • 12080

                #8
                Re: [TUTORIAL] Creating a login script for multiple users.

                Read the installation instructions here
                Navaldesign
                Logger Lite: Low Cost, Customizable, multifeatured Login script
                Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                Comment

                • konnectedservices
                  Private

                  • Jul 2006
                  • 3

                  #9
                  Re: [TUTORIAL] Creating a login script for multiple users.

                  Thanks nbop and other member for the tutorial creating vbmenu_register("postmenu_48386", true); login for multiple user, however, have created this on my site but don´t know what to do next, what area of my cpanel will i load this into as i am using cpanel and how do i create an account for the user so that as soon as he signin he will see his information, secondly do i need to create database for the login form and who. i will hope to hear from you soon about this

                  Comment

                  • navaldesign
                    General & Forum Moderator

                    • Oct 2005
                    • 12080

                    #10
                    Re: [TUTORIAL] Creating a login script for multiple users.

                    I'm afraid that the above script is not so automated. After a user has registered, you have to MANUALLY insert his username and password in the script as described above. Then you must upload again the updated script to your server and then let the new member know that he / she can go on visiting your site. Till you do this, he / she won't be able to loggin.
                    You don't need to create a database, not with this script.
                    Navaldesign
                    Logger Lite: Low Cost, Customizable, multifeatured Login script
                    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                    Comment

                    • konnectedservices
                      Private

                      • Jul 2006
                      • 3

                      #11
                      Re: [TUTORIAL] Creating a login script for multiple users.

                      Thanks for the reply what i am saying about is this, i have a site which have a registration page and login page, when a user register his information to the site throught eh login page what do i do next and how do i direct his register information to a page he will see when he login, i have don the pages discribe before but i want to know how i can setup a database for it as i am using cpanel

                      Comment

                      • navaldesign
                        General & Forum Moderator

                        • Oct 2005
                        • 12080

                        #12
                        Re: [TUTORIAL] Creating a login script for multiple users.

                        The above script doesn't make use of a database. Also, it doesn't describe how to make a registration form. You need to
                        1. Create aregistration form where the user fills in his desired username and password along with other information. Set the form so that the info is sent to you through an email. Update the script with the new username and password, and re-upload it on the server. Let the user know that his registration has been approved and he may now loggin in your site.
                        Navaldesign
                        Logger Lite: Low Cost, Customizable, multifeatured Login script
                        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                        Comment

                        • greyhame
                          Sergeant

                          • Jun 2006
                          • 36

                          #13
                          Re: [TUTORIAL] Creating a login script for multiple users.

                          This script can be inserted into a Blue Voda page simply by using the html tool at the top of the left toolbar to insert an html box. Double-click the box to open it and paste in the code. The php code will be embedded in the page. However, there seems to be a problem with the script. This appears above the form fields for the Name and Password before and information is entered:

                          Username or password is incorrect!
                          Please try again.</B>"); } ?>
                          No matter how fast you are going, there is always someone trying to pass.

                          Comment

                          • greyhame
                            Sergeant

                            • Jun 2006
                            • 36

                            #14
                            Re: [TUTORIAL] Creating a login script for multiple users.

                            also tried this by uploading the php file to my server. When I ran it I got the following error:
                            Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/colescom/public_html/FormTools/phptest.php on line 8 Areany values supposed to load values supposed to be modified before running the script?
                            No matter how fast you are going, there is always someone trying to pass.

                            Comment

                            • konnectedservices
                              Private

                              • Jul 2006
                              • 3

                              #15
                              Re: [TUTORIAL] Creating a login script for multiple users.

                              Thanks i got ur explainatioon about the application form, plz can you give me step by step what files to create and what directory are needed to work all this and how do. where do i do when the information on the application form has been sent my email . what thing he see when i register user login

                              Comment

                              Working...
                              X