www.webdeveloper.com
Results 1 to 9 of 9

Thread: Login System where users can login and read safety forms and agree to them weekly.

  1. #1
    Join Date
    Apr 2013
    Posts
    5

    Login System where users can login and read safety forms and agree to them weekly.

    Hello everyone,

    I am new to this forum and unsure where to post my question about this so I figured the "general," category. Here is what I am trying to do:

    1) Create a login interface/system where I am able to create multiple logins for different users for a company I work for.

    2) Once logged in these employees are going to view weekly documents on informative or safety documents. These documents will have some type of timer to prevent speeding through them.

    3) The employees will submit or confirm in some way that they have read the document and it will be recorded in a log per user that they have read the current document for the week.

    4) Every couple of days or week we will have a new document for the employees to read.

    5) The forms can be in formats of .doc, .pdf, .xlsx, etc., or just a regular plain text.

    This system will be entirely simple and nothing fancy is required as long as the information is passed along everyone and we have a record of who has read it.

    My questions is, what would be the best route or types of languages to involve in something like this? I am a little familiar with most of the languages but not a guru that is why I am here to get some help from the real gurus. Thank you!

  2. #2
    Join Date
    Apr 2013
    Posts
    56
    Hello,

    If web application will be as simple as you have described, I do not think you will be limited on what language/framework/CMS to pick. My recommendation is to pick language you are most comfortable with. That way development will go faster and you will save time and with it, money. Perhaps you can even try picking Drupal CMS since it has a very nice built-in user system and it should not be too hard to extend it the way you want.

  3. #3
    Join Date
    Apr 2013
    Posts
    5
    Hi Thanks for the response coding123. Ok so I happen to get my mysql and php to work with a very simple login page, now I would like to see if I can get some help with how to redirect to a "php/html" page only if login is successful. I do not want the page to be accessible without logging in

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    My preferred solution is to avoid the use of redirects. Instead create a file with all the necessary functionality to handle user authentication. Then you simply require() that file as the first thing you do on any page that requires the user be logged in. The include file includes the login form, and that form's action points to itself (action=""). The flow within the include file is something like:

    login.php:
    PHP Code:
    <?php
    session_start
    ();
    if(isset(
    $_POST['login_name'])) {
      if(!
    $validateLogin()) {
        
    displayLoginPage();
      }
    }
    elseif(empty(
    $_SESSION['user_id'])) {
      
    displayLoginPage();
    }

    function 
    validateLogin()
    {
      
    // process form data here
      // if login is okay, set necessary session data and return true, else return false
    }

    function 
    displayLoginPage()
    {
      
    // code or include() to display the login page
      
    exit; // <------ so that the rest of the calling page does not get processed/output
    }
    some_page.php:
    PHP Code:
    <?php
    require '/path/to/login.php';
    ?>
    <html>
    <head><title>test</title></head>
    <body>
    <p>top secret stuff</p>
    </body>
    </html>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Apr 2013
    Posts
    5
    Hi,

    So this is what I have as of right now:

    "logged.php"
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    body {
    background-color: #FFF;
    }
    body,td,th {
    color: #000;
    }
    </style>
    </head>

    <body>
    <p>&nbsp;</p>
    <div align="center">
    <table width="650" border="0">
    <tr>
    <td><p align="center">&nbsp;</p>
    <p align="center">Hi, this is the testing page. </p></td>
    </tr>
    </table>
    </div>
    <p>&nbsp;</p>
    </body>
    </html>

    "login.php"
    <?php
    session_start();

    $host = "db_access";
    $user = "username";
    $pass = "password";
    $db = "test";

    mysql_connect($host, $user, $pass);
    mysql_select_db($db);

    if (isset($_POST['username'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $sql = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1";
    $res = mysql_query($sql);
    if (mysql_num_rows($res) == 1) {
    echo "You have successfully logged in.";
    session_start();
    $_SESSION['cname'] = $name;
    header ("location: logged.php");
    exit ();

    } else {
    echo "Invalid login information. Please return to the previous page.";
    exit ();
    }
    }
    ?>




    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <style type="text/css">

    </style>
    </head>

    <body>
    <form method="post" action"login.php">

    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <table width="650" border="0" align="center">
    <tr>
    <td><div align="center"><br />
    <table width="650" border="0">
    <tr>
    <td><p align="center">Username:
    <input type="text" name="username" />
    <br />
    <br />
    Password:
    <input type="password" name="password" />
    </p>
    <p align="center">
    <input type="submit" name="submit" value="Log In" />
    </p></td>
    </tr>
    </table>
    <br />
    </div></td>
    </tr>
    </table>

    </form>
    </body>
    </html>


    You can test it out here:
    iwirelessevolution.com/airwavesafety/login.php
    username: username
    password: 1234

    My question is, how can I only allow access to the page if only the username and password is correct. Because right now I can launch the logged.php without logging in and I am able to access that page. I am really new to php coding so I need some help the most simplest way.

    My goal of the project is to create a simple login to a "safety" database where couple days I can upload a new file to "read" and after the file is read, the person that is logged in can click some type of submit button to mark it as complete. Each user will have the same files but must login individually and mark as read meaning 1 user will only effect themselves when reading the document.

    Structure of what I trying to do:

    1) Login screen.
    2) Login to "home page" for each user that can only be launched when their username & password submitted is valid.
    3) They will login, be able to read a file either from a link or text and have an option of marking it "as read," then it will store it in some type of date category so they can go back to it.
    4) This login system should be simple and solely only for reading a document, agreed they have read it and logout.
    5) As an admin we should be able to keep a log of who has logged in and read which document.
    6) I have access to mysql/sql server and godaddy windows hosting server iis7 asp.net 4.0 php version 5.3.

    Thank you for everyones help!

  6. #6
    Join Date
    Apr 2013
    Posts
    5
    Can anyone help with this? Thank you.

  7. #7
    Join Date
    Apr 2013
    Posts
    12
    weekly? what about once in two weeks? are you trying to scare people?

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    There are two basic approaches (that come to my mind right now, anyway):

    1. Every page that is to have controlled access must be a PHP page, and must include code to check if the requester is logged in or not, and if not then take appropriate action (e.g. send them to a log page, or provide a link to the login page, etc.). See my previous reply for one approach of this type.

    2. Store all controlled files outside of the web document root directory tree, create a single page that serves up the controlled pages (typically via include()) based on GET URL params -- possibly using web server URL rewriting to make the URLs more user-/SEO-friendly. If that sounds like a lot of gobbledy-gook to you, you're probably better off using the approach in #1.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Apr 2013
    Posts
    5
    Lol, why not scare them?

Thread Information

Users Browsing this Thread

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

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
  •  
HTML5 Development Center



Recent Articles