<file_sep><?php
session_start();
include 'header.php';
include 'functions.php';
$email=$password=$name=$lastname="";

if (isset($_SESSION['useremail'])) destorySession();

if (isset($_POST['email'])&&isset($_POST['password'])&&isset($_POST['name'])&&isset($_POST['lastname'])) {
	
	$conn=dbConnect();
	$email=sanitizeString($conn,$_POST['email']);
	$password=sanitizeString($conn,$_POST['password']);
	$name=sanitizeString($conn,$_POST['name']);
	$lastname=sanitizeString($conn,$_POST['lastname']);
	
	if ($email==""||$password=="") {
		echo "<script>alert(\"** Must input all fields.**\");</script>";
		mysqli_close($conn);
	}else {
		if (filter_var($email,FILTER_VALIDATE_EMAIL)) {
			mysqli_autocommit($conn, false);
			$query="SELECT * FROM user WHERE Email='$email' for update";
			$ris=mysqli_query($conn, $query);
			if (!$ris) {
				die('Query Failed\n');
			}
			
			if (mysqli_fetch_array($ris)==NULL) {
				$shaPassword=md5($password);
				$time=time();
			
						$sql = "INSERT INTO `dbtorino`.`user`(`Email`,`Password`,`Name`,`Lastname`,`Time`, `THR`) VALUES ('".
								$email."', '".$shaPassword."','".$name."','".$lastname."', '".$time."', ' ')";
			
			if (!@mysqli_query($conn, $sql)) {
				mysqli_rollback($conn);
				die("Query error:".$sql."<br>".mysqli_error($conn));
			}
			mysqli_commit($conn);
			mysqli_close($conn);
			
			$_SESSION['useremail']=$email;
			$_SESSION['password']=$<PASSWORD>;
			$_SESSION['lasttime']=$time;
			
			header('location:login.php');
			exit;
		}else{ 	
				   echo "<script>alert(\" Duplicated Register\");</script>";
				   mysqli_close($conn);
			    }
		}else{
			echo "<script>alert(\" Incorrect email format!\");</script>";
			mysqli_close($conn);
		 }
  }
}
?>
<!DOCTYPE HTML>
<html lang="en">
 <head>
   <link rel="stylesheet" type="text/css" href="css/style.css"/>
   <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/> 
   <title>Torino_Register</title>
 </head>
 <body>
  <div class="wrap">
    <div class="header">
     <img src="img/wrapper.JPG" width="100%" height="250px" alt="headerphoto" class="no-border">
    </div>
  
  <div class="navbar">
   <a class="active" href="home.php">Home</a>
   <a id="login "href="login.php">Login</a>
   <a id="register" href="register.php">SignUp</a>
   <a id="about" style="float:right" href="about.php">About</a>
  </div>
  
  <div class="main">
    <noscript>
	  <p style="color:red">Unfortunately your browser <strong>does not support Javascript</strong> and some functionality are not available!<br>
	  For a better browsing experience we recommend you to remedy. <a href="http://www.enable-javascript.com/" target="_blank">Here </a>
	  are the	instructions how to enable JavaScript in your web browser.</p>
      </noscript>
    <h1>User Register</h1>
    <div class="userlogin">    
         <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
         <p >* Required, email format: <EMAIL></p>     
         <p>Name:</p>
         <p><input id="a" type="text" name="name" title="Name" placeholder="Name" 
         value=<?php echo $name;?>><span class="error" >* </span></p>
         <p>Lastname:</p>
         <p><input id="a" type="text" name="lastname" placeholder="Last Name"
          title="Last Name" value=<?php echo $lastname;?>><span class="error" >* </span></p>       
         <p>Email:</p>
         <p><input id="a" type="text" name="email" placeholder="Email Adress" 
	     title="example: <EMAIL>" value=<?php echo $email;?>><span class="error">* </span></p>
         <p>Password:</p>
         <p><input id="a" type="password" name="password" placeholder="<PASSWORD>" 
         title="password"><span class="error">* </span></p>       
         <p style="text-align: center"><input  type="submit" name="commit" value="Register"></p>
         </form>
        </div>
  </div>
  
  <div class="footer">
   <p>&copy;2018 <strong>Created</strong> All rights deserved. contact: <NAME> <EMAIL></p>
  </div>
  </div>
  

 </body>
 
</html><file_sep><?php
session_start();
include "header.php";
include "functions.php";
if(!isset($_SESSION['useremail'])){
	header('location:login.php');
}


?>
<!DOCTYPE HTML>
<html lang="en">
 <head>
   <link rel="stylesheet" type="text/css" href="css/style.css"/>
   <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/> 
   <title>Torino_Homepage</title>
   
 </head>
 
 <body>
  <div class="wrap">
    <div class="header">
     <img src="img/wrapper.JPG" width="100%" height="250px" alt="headerphoto" class="no-border">
    </div>
  
  <div class="navbar">
   <a class="active" href="home.php">Home</a>
   <a id="login"     href="login.php">Login</a>
   <a id="register"  href="register.php">SignUp</a>
   <a id="about"     style="float:right" href="about.php">About</a>
  </div>
  
  <div class="main">
       <noscript>
	  <p style="color:red">Unfortunately your browser <strong>does not support Javascript</strong> and some functionality are not available!<br>
	  For a better browsing experience we recommend you to remedy. <a href="http://www.enable-javascript.com/" target="_blank">Here </a>
	  are the	instructions how to enable JavaScript in your web browser.</p>
      </noscript>
      
      
  </div>
  
  <div class="footer">
  <p>&copy;2018 <strong>Created</strong> All rights deserved. contact: YAXUE DU <EMAIL></p>
  </div>
  </div>
 </body>
 
</html><file_sep># text
php program---trying hard

folder img:The needed images  
folder css:The css style  
about.php  
functions.php   
header.php  
home.php  
login.php   
logout.php   
main.php   
register.php  
<description: In this project,I learned how to write php code to do the user register and user login>
<file_sep><?php
//sanitize input string
function sanitizeString($conn,$var) {
	$var = trim($var);
	$var = htmlentities($var);
	$var = stripcslashes($var);

	$var = mysqli_real_escape_string($conn,$var);
	return $var;
}

$servername = 'localhost';
$username = 'root';
$password = '';
$database = 'dbtorino';

// connect to the DB
// return connection handle
function dbConnect() {
	//a variable declared within a function with the global qualifier has the global scope
	global $servername;
	global $username;
	global $password;
	global $database;
	
	$conn = @mysqli_connect( $servername, $username, $password, $database);
	if(mysqli_connect_error())
		die("Database connection failed:"
				.mysqli_connect_errno()."-----".mysqli_connect_error());
	if(!@mysqli_select_db($conn,$database))
			die("Database selection error: ".mysqli_error($conn));
	return $conn;
}

//store the user register
function storeRegister($email,$password,$name,$lastname) {
	$conn = dbConnect();
	$sql = "INSERT INTO `dbtorino`.`user`(`Email`,`Password`,`Name`,`Lastname`,'Time','THR') 
			VALUES ('".$email."', '".$shaPassword ."','".$name."','".$lastname."','".$time."','.$thr.')";
	if (!@mysqli_query($conn, $sql)) {
		die("Query error: ". $sql. "<br>". mysqli_error($conn));
	}
	mysqli_close($conn);
}
//normal mysqli_query
function normalQuery($conn, $query)
{
	$result = mysqli_query($conn, $query);
	if (!$result){
		mysqli_close($conn);
		die('Normal SQL fail.');
	}
	return $result;
}
// check given username and password
// return true if user exists with given username and password
function validUser($user, $password) {	
	$conn = dbConnect();	
	$sql = "SELECT Password FROM user WHERE Email ='". $user . "'";
	$resp = @mysqli_query($conn,$sql);
	if(!$resp)
		die("Error in query: ".$sql."<br>".mysqli_error($conn));
		if (mysqli_num_rows($resp) == 0){
			return FALSE;
		}
		$row = mysqli_fetch_array($resp);
		$res = ($password == $row[0]);
		mysqli_close($conn);
		return ($res);     //return  true;
}

?><file_sep><?php
session_start();
include 'header.php';
include 'functions.php';
$useremail=$password='';

if($_SERVER["REQUEST_METHOD"] == "POST"){
 if(isset($_POST['useremail'])&&isset($_POST['password'])) {
	$connect = dbConnect();	
	$useremail = sanitizeString($connect,$_POST['useremail']);
	$password = sanitizeString($connect,$_POST['password']);
 
 	if (empty($useremail||empty($password))){
        echo "<script>alert(\" **Must input all fields.**\");</script>";	
        mysqli_close($connect);
        
	}else{
		$sql = "SELECT * 
		        FROM user 
		        WHERE Email ='$useremail'";		 
			$result = normalQuery($connect, $sql);
			$arr = mysqli_fetch_array($result);
			$row = mysqli_num_rows($result);
			if($row==0){
				echo "<script>alert(\"Username does not exist!\");</script>";
				mysqli_close($connect);
			}elseif(strcmp($arr['Password'], md5($password))!=0){
				echo "<script>alert(\"Password is error!\");</script>";
				mysqli_close($connect);
			}
			else
			{
				$_SESSION['useremail'] = $useremail;
				$_SESSION['password'] = $<PASSWORD>;
				$_SESSION['lasttime'] = time();
				//echo "<script>alert(\"You have logged in!\");</script>";
				header('location:main.php');
				exit;
			}
	 
	}
 }
}
session_unset();
?>
<!DOCTYPE HTML>
<html lang="en">
 <head>
   <link rel="stylesheet" type="text/css" href="css/style.css"/>
   <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/> 
   <title>Torino_Login</title>
 </head>
 <body>
  <div class="wrap">
    <div class="header">
     <img src="img/wrapper.JPG" width="100%" height="250px" alt="headerphoto" class="no-border">
    </div>
  
  <div class="navbar">
   <a class="active" href="home.php">Home</a>
   <a id="login "href="login.php">Login</a>
   <a id="register" href="register.php">SignUp</a>
   <a id="about" style="float:right" href="about.php">About</a>
  </div>
  
  <div class="main">
    <noscript>
	  <p style="color:red">Unfortunately your browser <strong>does not support Javascript</strong> and some functionality are not available!<br>
	  For a better browsing experience we recommend you to remedy. <a href="http://www.enable-javascript.com/" target="_blank">Here </a>
	  are the	instructions how to enable JavaScript in your web browser.</p>
      </noscript>
    <h1>User Login</h1>
    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
     <div class="userlogin">
      <p>User Name</p>
      <p><input type="text" id="a" name="useremail" placeholder="Email Address" value=<?php echo $useremail;?>><span class="error" >* </span></p>
      <p>Password</p>
      <p><input type="<PASSWORD>" id="a" name="password" placeholder="<PASSWORD>"><span class="error" >*</span></p>    
      <p style="text-align: center"><input type="submit" name="commit" value="Login"/></p>     
     </div>
    
    </form>
    
  </div>
  
  <div class="footer">
   <p>&copy;2018 <strong>Created</strong> All rights deserved. contact: <NAME> <EMAIL></p>
  </div>
  </div>
  

 </body>
 
</html><file_sep><?php
/*if(empty($_SERVER['HTTPS'])||$_SERVER['HTTPS']!='on'){
 header('Location:https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],TRUE,301);
die();
}
*/
if(isset($_SESSION['lasttime'])){
	if(time()-$_SESSION['lasttime']>120){
		unset($_SESSION['lasttime']);

		session_destroy();
		header('Location: logout.php?msg=SessionTimeOut');
		exit;
	} else {
		$_SESSION['lasttime']=time(); /* update time */

	}
}
?>
<file_sep><?php
session_start();
include 'header.php';
include 'functions.php';
?>
<!DOCTYPE HTML>
<html lang="en">
 <head>
   <link rel="stylesheet" type="text/css" href="css/style.css"/>
   <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/> 
   <title>Torino_Homepage</title>
 
 </head>
 
 <body>
  <div class="wrap">
    <div class="header">
     <img src="img/wrapper.JPG" width="100%" height="250px" alt="headerphoto" class="no-border">
    </div>
  
  <div class="navbar">
   <a class="active" href="home.php">Home</a>
   <a id="login"     href="login.php">Login</a>
   <a id="register"  href="register.php">SignUp</a>
   <a id="about"     style="float:right" href="about.php">About</a>
  </div>
  
  <div class="main">
       <noscript>
	  <p style="color:red">Unfortunately your browser <strong>does not support Javascript</strong> and some functionality are not available!<br>
	  For a better browsing experience we recommend you to remedy. <a href="http://www.enable-javascript.com/" target="_blank">Here </a>
	  are the	instructions how to enable JavaScript in your web browser.</p>
      </noscript>
      <div style="float: left;clear:both">
        <img id=1_0 width="997" height="600" src="img/p1.jpg" alt="Iphone 7"  style='float:left'>
	    <br><br><br><br><br><br><br><br><br>
	 	
	   <ul style='float: left' class="menu">
		<li id=1_1 class="current"><a>pic1</a></li>
		<li id=2_2><a>pic2</a></li>
		<li id=3_3><a>pic3</a></li>
		<li id=4_4><a>pic4</a></li>
		<li id=5_5><a>pic5</a></li>
		<li id=6_6><a>pic6</a></li>
	  </ul>
	   </div>  
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
   <script>
     $(document).ready(function(){
	    $("#1_1").mouseover(function(){
	        $("#1_0").attr("src", "img/p1.jpg");
	    });
	    $("#2_2").mouseover(function(){
	        $("#1_0").attr("src", "img/p2.jpg");
	    });
	    $("#3_3").mouseover(function(){
		    $("#1_0").attr("src", "img/p3.jpg");
		});
		$("#4_4").mouseover(function(){
		    $("#1_0").attr("src", "img/p4.jpg");
		});   
		$("#5_5").mouseover(function(){
		    $("#1_0").attr("src", "img/p5.jpg");
		});
		$("#6_6").mouseover(function(){
		    $("#1_0").attr("src", "img/p6.jpg");
		});
	   });
     </script>
<!-- 
	<ul class="slide-pic">
		<li class="current"><img width="997" height="600"  src="img/p1.jpg" /></li>
		<li><img width="997" height="600" src="img/p2.jpg" /></li>
		<li><img width="997" height="600" src="img/p3.jpg" /></li>
		<li><img width="997" height="600" src="img/p4.jpg" /></li>
	    <li><img width="997" height="600" src="img/p5.jpg" /></li>
	</ul>
	 <ul class="slide-li op">
		<li class="current"></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
	</ul>
	<ul class="slide-li">
		<li class="current"><a>pic1</a></li>
		<li><a>pic2</a></li>
		<li><a>pic3</a></li>
		<li><a>pic4</a></li>
		<li><a>pic5</a></li>
		
	</ul>   -->
  </div>
  
  <div class="footer">
  <p>&copy;2018 <strong>Created</strong> All rights deserved. contact: <NAME> <EMAIL></p>
  </div>
  </div>
 </body>
 
</html>