Fandom

PHP Wiki

Login Script

51pages on
this wiki
Add New Page
Talk3 Share
<?php
session_start();
mysql_connect($server, $user, $password) or die(mysql_error()); //Connect to MySQL Server
mysql_select_db($my_db) or die(mysql_error()); //Select MySQL Database
 
if (isset($_POST['submit'])) {
 
		$user=mysql_real_escape_string($_POST['username']); //Escapes String Characters in Username
		$pass=md5($_POST['password']); //Encrypts Password
		$sql = "SELECT * FROM users WHERE username='{$user}' && password='{$pass}'"; // SQL Quary
		$result= mysql_num_rows(mysql_query($sql));
 
		if ($result == 1) {
 
			$_SESSION['logged'] = true;
         		$_SESSION['username'] = $user;
        		$_SESSION['password'] = md5($_POST['password']);
      			header('Location:../index.php');
		 		echo 'Login Successful';
 
						  }
 
 
		else {
	 		$_SESSION['logged'] = false;
			header('Location:../index.php?error=login');
			echo '<p>Incorrect Login please try again</p>';
			}
	}
 
?>

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.