Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board Login.php Download Source Code
Author Details Code Information
Relish ( Mike )

Pinned 3 Codes
Posted 1 Coding Articles

Send A Message
View Coders Profile
Language PHP (Hypertext Preprocessor)
Expires Never
Length 3,004 Characters (81 Lines)
Password no password
  1. <?php
  2.        session_start();
  3.        /* This page checks user information and
  4.         * logs them in if it's correct.
  5.         *
  6.         * First, we need to check if the form has
  7.         * been submitted. If it has, we need to check
  8.         * form values, to make sure they filled them in
  9.         * right.
  10.         *
  11.         * Connect to MySQL and check if the form has
  12.         * been submitted:
  13.         */
  14.        // Connect to MySQL. Change the values to your information:
  15.        $mysql = mysqli_connect('localhost', 'username', 'password', 'database') or die('An error has occured.');
  16.        // Check if the form has been submitted:
  17.        if(isset($_POST['username']) && isset($_POST['passsword'])) {
  18.               // Now we check that both forms were filled in:
  19.               if(!empty($_POST['username']) && isset($_POST['password'])) {
  20.                      // We're all good, so we can assign the post values to variables:
  21.                      extract($_POST);
  22.                      /* Now we can refer to $_POST['username'] as
  23.                       * $username. It's much faster and easier. We
  24.                       * user extract() because it's easier than
  25.                       * doing it manually. Caution: May make you lazy
  26.                       * :P
  27.                       *
  28.                       * Now we can query our database for the username
  29.                       * and password combonation. If it returns no rows
  30.                       * with the inputted password AND username, either
  31.                       * the password does not match the username, or the
  32.                       * user inputted information that does not exist.
  33.                       *
  34.                       * We can assign the user id to a session, and use
  35.                       * that to retrieve all the information about the
  36.                       * user from the table.
  37.                       */
  38.                      if($query = $mysql->prepare('SELECT userid FROM users WHERE username = ? AND password = ?')) {
  39.                             $query->bind_param('ss', $username, $password);
  40.                             $query->execute();
  41.                             $query->store_result();
  42.                             /* Now we count the number of rows returned. As
  43.                              * I stated before, if the number of rows is less
  44.                              * than one, the user has failed to input valid
  45.                              * information.
  46.                              */
  47.                             if($query->num_rows < 1) {
  48.                                    // Login unsuccessful. Echo error:
  49.                                    echo('Incorrect information provided. Login failed.');
  50.                             } else {
  51.                                    /* The login was successful! We need to assign the user
  52.                                     * id to a session for later use (retrieving information,
  53.                                     * etc). First however, we need to retrieve the user id:
  54.                                     */
  55.                                    $query->bind_result($userid);
  56.                                    if($query->fetch()) {
  57.                                           // Assign the user id to a session:
  58.                                           $_SESSION['userid'] = $userid;
  59.                                           // Redirect user to the logged in page:
  60.                                           header('Location: loggedin.php');
  61.                                    }
  62.                             }
  63.                      } else {
  64.                             // The query failed to be prepared:
  65.                             die('An error has occured.');
  66.                      }
  67.               }
  68.        }
  69. ?>
  70. <!-- Login Form -->
  71. <form action="login.php" method="post">
  72.        <fieldset>
  73.               <legend>Login To Your Account</legend>
  74.               <label for="username">Username:</label> <input type="text" id="username" name="username" /><br />
  75.               <label for="password">Password:</label> <input type="password" id="password" name="password" /><br />
  76.               <input type="submit" name="submit" value="Login" />
  77.        </fieldset>
  78. </form>
  79. <!-- End Login Form -->
code pin board Back To Code Pin Board Post New Code
Please login to post comments.
 
Danny     Posted 3.15 Years Ago
 
 
so this piece of script perpers for the profile page like gets the user name and
everything and logs them in so how would i go about make the profile page would u use
the userid and display anything to do with that user
 
Danny     Posted 3.15 Years Ago
 
 
so this piece of script perpers for the profile page like gets the user name and
everything and logs them in so how would i go about make the profile page would u use
the userid and display anything to do with that user
Page 1 of 1
 
 
Latest News About Coder Profile
Coder Profile Poll
Why do you get bored with programming?

Not enough time to do something productive
I run out of ideas
Too hard to show people my creations
Everything i do has too many errors, and it's too hard
I don't get bored!!!


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.19 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved