Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //You will want to create a database connection class
- //in the future instead of using variables
- $dbhost = ''; //Database host
- $dbuser = ''; //Database username
- $dbpass = ''; //Database password
- $dbname = ''; //Database name
- //Connect to MySQL
- $con = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
- if (mysqli_connect_errno())
- {
- echo 'Cannot connect to the database:' mysqli_connect_error();
- }
- //Check the user
- if(isset($_POST['login']))
- {
- $user = mysqli_real_escape_string($con,$_POST['user']);
- $pass = mysqli_real_escape_string($con,$_POST['pass']);
- $run_user = mysqli_query($con, "SELECT * FROM `UserName` WHERE userName = '$user' AND pass = '$pass'");
- $check_user = mysqli_num_rows($run_user);
- if($check_user > 0)
- {
- $cookie_name = "user";
- setcookie($cookie_name, $user, time() + (86400), "/"); //Set cookie for 1 day
- $_SESSION['User'] = $user;
- echo "Logging in as ".$user."...";
- header("Location: /adminpanel.php"); //Use header instead of a javascript
- exit;
- }
- else
- {
- echo "Error during login, check user/pass";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement