Advertisement
DrRush12358

login portal

Feb 20th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.37 KB | None | 0 0
  1. <?php
  2.    session_start();
  3.  
  4. /*
  5.  * Copyright 2016 James.
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *      http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20.  //login checks given info against the database
  21.     function login(){
  22.         $user = $_POST['username'];
  23.         $password = $_POST['password'];
  24.        
  25.         //get db data
  26.        
  27.         $db = new PDO('mysql:host=localhost;dbname=dbname;charset=utf8', 'user', 'password');
  28.         $stmt = $db->prepare('SELECT * FROM login_info WHERE username=:user AND password=:pass AND usergroup=:group AND beta=:beta');
  29.         // Perform queries
  30.         $stmt->bindValue(':id', $db_user, PDO::PARAM_STR);
  31.         $stmt->bindValue(':pass', $db_password, PDO::PARAM_STR);
  32.         $stmt->bindValue(':group', $db_usergroup, PDO::PARAM_STR);
  33.         $stmt->bindValue(':beta', $db_beta, PDO::PARAM_INT);
  34.         $stmt->execute();
  35.         $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
  36.        
  37.         //check user data against the database
  38.         if($db_user == $user && $db_password == $password){
  39.             //set session
  40.            
  41.             $_SESSION['logstat'] = true;
  42.             $_SESSION['group'] = $db_usergroup;
  43.             $_SESSION['beta'] = $db_beta;
  44.         }
  45.     }
  46.  
  47. ?>
  48.  
  49. <!doctype html>
  50. <html>
  51.     <head>
  52.         <title>PWStats | Home</title>
  53.         <meta charset="UTF-8">
  54.         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  55.     </head>
  56.    
  57.     <body>
  58.         <p>This is text.</p>
  59.        
  60.         <form action="login.php" method="post">
  61.             <fieldset>
  62.                 <legend>Login</legend>
  63.                 User Name:<br>
  64.                 <input type="text" name="username"><br>
  65.                 Password:<br>
  66.                 <input type="password" name="password"><br>
  67.                 <input type="submit" value="Submit">
  68.             </fieldset>
  69.         </form>
  70.        
  71.     </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement