Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- /*
- * Copyright 2016 James.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- //login checks given info against the database
- function login(){
- $user = $_POST['username'];
- $password = $_POST['password'];
- //get db data
- $db = new PDO('mysql:host=localhost;dbname=dbname;charset=utf8', 'user', 'password');
- $stmt = $db->prepare('SELECT * FROM login_info WHERE username=:user AND password=:pass AND usergroup=:group AND beta=:beta');
- // Perform queries
- $stmt->bindValue(':id', $db_user, PDO::PARAM_STR);
- $stmt->bindValue(':pass', $db_password, PDO::PARAM_STR);
- $stmt->bindValue(':group', $db_usergroup, PDO::PARAM_STR);
- $stmt->bindValue(':beta', $db_beta, PDO::PARAM_INT);
- $stmt->execute();
- $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
- //check user data against the database
- if($db_user == $user && $db_password == $password){
- //set session
- $_SESSION['logstat'] = true;
- $_SESSION['group'] = $db_usergroup;
- $_SESSION['beta'] = $db_beta;
- }
- }
- ?>
- <!doctype html>
- <html>
- <head>
- <title>PWStats | Home</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- </head>
- <body>
- <p>This is text.</p>
- <form action="login.php" method="post">
- <fieldset>
- <legend>Login</legend>
- User Name:<br>
- <input type="text" name="username"><br>
- Password:<br>
- <input type="password" name="password"><br>
- <input type="submit" value="Submit">
- </fieldset>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement