Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if (isset($_POST['submit'])) {
- // $lines is missing here just to avoid any problems.. but the connection to my db is working perfect..
- $uid = trim($lines[0]);
- $pw = trim($lines[1]);
- $dbserver = trim($lines[2]);
- $dbname = trim($lines[3]);
- $userId = $_POST['username'];
- $passId = $_POST['pwd'];
- $messageErr = "";
- $messageValid = "";
- $valid = True;
- //Connect to the mysql server and get back our link_identifier
- $link = mysqli_connect($dbserver,$uid,$pw,$dbname) or die('Could not connect: ' . mysqli_error($link));
- $db_selected = mysqli_select_db($link, $dbname) or die ('Can not use int322 : ' . mysqli_error($link));
- $name = mysqli_real_escape_string($link, $_POST['username']); // The function mysql_real_escape_string() stops hackers!
- $pass = mysqli_real_escape_string($link, $_POST['pwd']); // We won't use MD5 encryption here because it is the simple tutorial, if you don't know what MD5 is, dont worry!
- $result = mysqli_query($link, "SELECT * FROM users WHERE username='$userId' AND password='$passId'"); // This code uses MySQL to get all of the users in the database with that username and password.
- $count = mysqli_num_rows($result);
- if ($count==1) {
- $row = mysqli_fetch_assoc($result);
- if ($passId == $row['password']){
- if (isset($_SESSION['loggedin'])) {
- echo "<form method='POST' action=''>";
- echo "<table>";
- echo "<tr><td><strong class='pass'>Login Successful</strong><br></td></tr>";
- echo "<tr><td><input type='submit' name='logout' value='Logout'></td></tr>";
- echo "</form>";
- echo "</table>";
- $logOut = $_POST['logout'];
- return true;
- }
- if (isset($_POST['logout'])) {
- echo "<strong>Logout Successful</strong>";
- session_destroy();
- //header("Location: login.php");
- } else {
- header("Location: login.php");
- }
- }
- else {
- $messageErr = "Invalid username or password!";
- $valid = false;
- }
- }
- else {
- $messageErr = "Invalid username or password!";
- $valid = false;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement