Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $username = "";
- $ID = "";
- $errorMessage = "";
- if (isset($_POST['submit'])) { //submit button has been clicked
- $username = $_POST['username']; //read in the value the user has entered for the username
- $username = htmlspecialchars($username); //prevent cross site scripting errors
- $username = strip_tags($username); //prevent cross site scripting errors
- $username = trim($username); //trim any whitespaces in the input value
- $ID = $_POST['ID'];
- $ID = htmlspecialchars($ID);
- $ID = strip_tags($ID);
- $ID = trim($ID);
- session_start(); //start a session
- $user_name = "root"; //default username for MySQL
- $password = ""; //default password for MySQL
- $database = "myapplication"; //name of db you created
- $server = "127.0.0.1"; //IP address of the database
- $db_handle = mysql_connect($server, $user_name, $password);
- $db_found = mysql_select_db($database);
- if(!$db_found) {
- print"Daabase NOT found" ;
- }
- else {
- $SQL = "SELECT * FROM login WHERE uname = "."'".$username."'". " AND ID = "."'"."$ID"."'";
- $result = mysql_query($SQL);
- $num_rows = mysql_num_rows($result);
- if ($num_rows > 0) {
- $_SESSION['login']="1"; //set the value of the 'login' session variable to '1
- $_SESSION['username']="Joe";
- header('Location: topSecret.php'); //redirect the user to topSecret.php page
- }
- }
- mysql_close($db_handle);
- /*
- if($username=="Joe" && $ID==1234) { //valid user
- // store session data
- $_SESSION['login']="1"; //set the value of the 'login' session variable to '1
- $_SESSION['username']="Joe";
- header('Location: topSecret.php'); //redirect the user to topSecret.php page
- } else {
- session_start(); //start
- $errorMessage = "Login Unsuccessful";
- $_SESSION['error']=$errorMessage; //sets the value of the 'errorMessage' session variable
- $_SESSION['login'] = ""; //set the value of the 'login' session variable to ''
- //redirect to login page & send error message
- header('Location: loginForm.php'); //redirect the user to the login page
- }
- */
- }
- ?>
Add Comment
Please, Sign In to add comment