首先我开始借口mysql
之前我知道它已经折旧了,我将来会更新到PDO。所以我们走了。
基本上我的大多数页面都有重复,'index.php','index2.php'依此类推。基本上现在所有没有数字'2'的页面都是非注册用户,一旦用户登录,它们将被重定向到'index2.php',因此所有带有'2'的数字都是注册用户页面。所以我基本上想做的是不是拥有重复的页面我能够只有'index.php'和其他没有重复的页面?因此,用户登录将重定向到'index.php',但具有相同的功能和'index2.php'。如果这有道理哈哈!
注册页码:
<?php
session_start();
include ('../includes/config.php');
include ('../includes/header.php');
?>
<!doctype html>
<html>
<body>
<div class="search1">
<h2>Register</h2>
<form action="" method="POST">
<center>
<label>Username:</label>
<input type="text" name="username" required />
<label>Password:</label>
<input type="password" name="password" required />
<label>Email:</label>
<input type="email" name="email" required />
<input type="submit" value="Register" name="submit" class="submit" />
</center>
<br><br><br>
<h2><p><a href="index.php">Back</a></p></h2>
</div>
<?php
if(isset($_POST["submit"])){
if(!empty($_POST['username']) && !empty($_POST['password'])) {
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$password = strip_tags($password);
$password = md5($password); // md5 is used to encrypt your password to make it more secure.
$con=mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('aha') or die("cannot select DB");
$query=mysql_query("SELECT * FROM login WHERE username='".$username."'");
$numrows=mysql_num_rows($query);
if($numrows==0)
{
$sql="INSERT INTO login(username,password,email) VALUES('$username','$password', '$email')";
$result=mysql_query($sql);
if($result){
echo "<div class='passed'>Account Successfully Created</div>";
} else {
echo "<div class='results'>Failure!</div>";
}
} else {
echo "<div class='results'>Username already exists!</div>";
}
} else {
echo "<div class='results'>All fields are required!</div>";
}
}
?>
</form>
<img src="../images/main.jpg">
</body>
</html>
INDEX1.PHP-CODE:
<?php
session_start();
include ('../includes/config.php');
include ('../includes/header.php');
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Honda |</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='http://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'>
<link href="../css/style.css" rel="stylesheet" type="text/css" media="all" />
<!--slider-->
<link href="../css/camera.css" rel="stylesheet" type="text/css" media="all" />
<script type='text/javascript' src='../js/jquery.min.js'></script>
<script type='text/javascript' src='../js/jquery.mobile.customized.min.js'></script>
<script type='text/javascript' src='../js/jquery.easing.1.3.js'></script>
<script type='text/javascript' src='../js/camera.min.js'></script>
<script>
jQuery(function(){
jQuery('#camera_wrap_1').camera({
thumbnails: true
});
jQuery('#camera_wrap_2').camera({
height: '400px',
loader: 'bar',
pagination: false,
thumbnails: true
});
});
</script>
</head>
<body>
<!--start header-->
<div class="h_bg">
<div class="wrap">
<div class="wrapper">
<div class="header">
<div class="logo">
<a href="index.php"><img src="../images/logo.png"> </a>
</div>
<div class="cssmenu">
<ul>
<li class="active"><a href="index.php"><span>Home</span></a></li>
<li><a href="about.php"><span>About</span></a></li>
<li class="has-sub"><a href="service.php"><span>Gallery</span></a>
</li>
<li class="last"><a href="contact.php"><span>Contact</span></a></li>
<div class="clear"></div>
</ul>
<div class="search">
<h2>search</h2>
<form action="search.php" method="get">
<input type="text" name="search" value="" placeholder="Enter Your search...">
<input type="submit" name="submit" value="">
</form>
</div>
<?php
if(isset($_POST["submit"])){
if(!empty($_POST['username']) && !empty($_POST['password'])) {
$username=$_POST['username'];
$password=$_POST['password'];
$password = strip_tags($password);
$password = md5($password); // md5 is used to encrypt your password to make it more secure.
$query=mysql_query("SELECT * FROM login WHERE username='".$username."' AND password='".$password."'");
$numrows=mysql_num_rows($query);
if($numrows!=0)
{
while($row=mysql_fetch_assoc($query))
{
$dbusername=$row['username'];
$dbpassword=$row['password'];
}
if($username == $dbusername && $password == $dbpassword)
{
session_start();
$_SESSION['sess_user']=$username;
/* Redirect browser */
header("Location: member.php");
}
} else {
echo "<div class='results'>Invalid username or password</div>";
}
} else {
echo "All fields are required!";
}
}
?>
<div class="search1">
<h2>login/Register</h2>
<form action="" method="POST">
<label>Username:</label>
<input type="text" id="password" name="username" required />
<label>Password:</label>
<input type="password" id="password" name="password" required />
<input type="submit" value="Login" name="submit" class="submit" />
<br><br>
<center>
<h2><p><a href="register.php">Register</a></p></h2>
</center>
</form>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<!-- start slider -->
<div class="slider_bg">
<div class="wrap">
<div class="wrapper">
<div class="slider">
<!-- #camera_wrap_1 -->
<div class="fluid_container">
<div class="camera_wrap camera_azure_skin" id="camera_wrap_1">
<div data-thumb="../images/thumbs/slider1.jpg" data-src="../images/slider/slider1.jpg">
</div>
<div data-thumb="../images/thumbs/slider2.jpg" data-src="../images/slider/slider2.jpg">
</div>
<div data-thumb="../images/thumbs/slider3.jpg" data-src="../images/slider/slider3.jpg">
</div>
<div data-thumb="../images/thumbs/slider4.jpg" data-src="../images/slider/slider4.jpg">
</div>
</div><!-- #camera_wrap_1 -->
<div class="clear"></div>
</div>
<!-- end #camera_wrap_1 -->
<div class="clear"></div>
</div>
</div>
</div>
</div>
<!-- start content -->
<div class="content_bg">
<div class="wrap">
<div class="wrapper">
<div class="main">
<!-- start content_right -->
<div class="image group">
<div class="grids_of_2">
<div class="grid images_3_of_1">
<img src="../images/pic1.jpg">
</div>
<div class="grid span_2_of_3">
<h3>How it all started</h3>
<p class="para">Honda Motor Co., Ltd. (本田技研工業株式会社 Honda Giken Kōgyō KK?, IPA: [hoɴda] ( listen); /ˈhɒndə/) is a Japanese public multinational corporation primarily known as a manufacturer of automobiles, motorcycles and power equipment.
Honda has been the world's largest motorcycle manufacturer since 1959,[3][4] as well as the world's largest manufacturer of internal combustion engines measured by volume, producing more than 14 million internal combustion engines each year.[5] Honda became the second-largest Japanese automobile manufacturer in 2001.[6][7] Honda was the eighth largest automobile manufacturer in the world behind General Motors, Volkswagen Group, Toyota, Hyundai Motor Group, Ford, Nissan, and PSA in 2011.[8]
Honda was the first Japanese automobile manufacturer to release a dedicated luxury brand, Acura, in 1986. Aside from their core automobile and motorcycle businesses, Honda also manufactures garden equipment, marine engines, personal watercraft and power generators, amongst others. Since 1986, Honda has been involved with artificial intelligence/robotics research and released their ASIMO robot in 2000. They have also ventured into aerospace with the establishment of GE Honda Aero Engines in 2004 and the Honda HA-420 HondaJet, which began production in 2012. Honda has three joint-ventures in China (Honda China, Dongfeng Honda, and Guangqi Honda).
In 2013, Honda invested about 5.7% (US$ 6.8 billion) of its revenues in research and development.[9] Also in 2013, Honda became the first Japanese automaker to be a net exporter from the United States, exporting 108,705 Honda and Acura models while importing only 88,357</p>
</div>
<div class="clear"></div>
</div>
<div class="grids_of_2 top">
<div class="grid images_3_of_1">
<img src="../images/pic2.jpg">
</div>
<div class="grid span_2_of_3">
<h3>CEO of Honda</h3>
<p class="para">Kawamoto acted quickly to change Honda's corporate culture, rushing through market-driven product development that resulted in recreational vehicles such as the Odyssey[disambiguation needed] and the CR-V, and a refocusing away from some of the numerous sedans and coupes that were popular with Honda's engineers but not with the buying public. The most shocking change to Honda came when Kawamoto ended Honda's successful participation in Formula One after the 1992 season, citing costs in light of the takeover threat from Mitsubishi as well as the desire to create a more environmentally-friendly company image.[21]
Later, 1995 gave rise to the Honda Aircraft Company with the goal of producing jet aircraft under Honda's name</p>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</center>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<div class="footer_bg">
<div class="wrap">
<div class="wrapper">
<div class="footer">
<div class="copy">
<p class="w3-link">© </p>
</div>
<div class="f_nav">
<ul>
<li><a href="#">Skype</a></li>
<li><a href="#">Linked in</a></li>
<li><a href="#">Twitter</a></li>
<li><a href="#">Facebook</a></li>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</body>
</html>
</body>
</html>
最少但不是最后! INDEX2.PHP-CODE:
<?php
session_start();
include "../includes/config.php";
include "function.php";
include ('../includes/header.php');
?>
<!DOCTYPE HTML>
<html>
<head>
<style>
#error_box{display:none; position:relative;top:-25px}
</style>
<title>Honda |</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='http://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'>
<link href="../css/style.css" rel="stylesheet" type="text/css" media="all" />
<!--slider-->
<link href="../css/camera.css" rel="stylesheet" type="text/css" media="all" />
<script type='text/javascript' src='../js/jquery.min.js'></script>
<script type='text/javascript' src='../js/jquery.mobile.customized.min.js'></script>
<script type='text/javascript' src='../js/jquery.easing.1.3.js'></script>
<script type='text/javascript' src='../js/camera.min.js'></script>
<script>
jQuery(function(){
jQuery('#camera_wrap_1').camera({
thumbnails: true
});
jQuery('#camera_wrap_2').camera({
height: '400px',
loader: 'bar',
pagination: false,
thumbnails: true
});
});
</script>
</head>
<body>
<!--start header-->
<div class="h_bg">
<div class="wrap">
<div class="wrapper">
<div class="header">
<div class="logo">
<a href="index2.php"><img src="../images/logo.png"> </a>
</div>
<div class="cssmenu">
<ul>
<li class="active"><a href="index2.php"><span>Home</span></a></li>
<li><a href="about2.php"><span>About</span></a></li>
<li class="has-sub"><a href="service2.php"><span>Gallery</span></a>
</li>
<li class="last"><a href="contact2.php"><span>Contact</span></a></li>
<div class="clear"></div>
</ul>
<div class="search">
<h2>search</h2>
<form>
<input type="text" value="" placeholder="Enter Your search...">
<input type="submit" value="">
</form>
</div>
<div class="search1">
<form action="" method="POST">
<br>
<h2>Welcome, <?=$_SESSION['sess_user'];?>!</h2><br><br>
<div class="pw">
<a href="changepassword.php"><h3>Change details</h3></a>
</div>
<br><br>
<h2><a href="logout.php">Logout</a></h2>
</form>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<!-- start slider -->
<div class="slider_bg">
<div class="wrap">
<div class="wrapper">
<div class="slider">
<!-- #camera_wrap_1 -->
<div class="fluid_container">
<div class="camera_wrap camera_azure_skin" id="camera_wrap_1">
<div data-thumb="../images/thumbs/slider1.jpg" data-src="../images/slider/slider1.jpg">
</div>
<div data-thumb="../images/thumbs/slider2.jpg" data-src="../images/slider/slider2.jpg">
</div>
<div data-thumb="../images/thumbs/slider3.jpg" data-src="../images/slider/slider3.jpg">
</div>
<div data-thumb="../images/thumbs/slider4.jpg" data-src="../images/slider/slider4.jpg">
</div>
</div><!-- #camera_wrap_1 -->
<div class="clear"></div>
</div>
<!-- end #camera_wrap_1 -->
<div class="clear"></div>
</div>
</div>
</div>
</div>
<!-- start content -->
<div class="content_bg">
<div class="wrap">
<div class="wrapper">
<div class="main">
<!-- start content_right -->
<div class="image group">
<div class="grids_of_2">
<div class="grid images_3_of_1">
<img src="../images/pic1.jpg">
</div>
<div class="grid span_2_of_3">
<h3>How it all started</h3>
<p class="para">Honda Motor Co., Ltd. (本田技研工業株式会社 Honda Giken Kōgyō KK?, IPA: [hoɴda] ( listen); /ˈhɒndə/) is a Japanese public multinational corporation primarily known as a manufacturer of automobiles, motorcycles and power equipment.
Honda has been the world's largest motorcycle manufacturer since 1959,[3][4] as well as the world's largest manufacturer of internal combustion engines measured by volume, producing more than 14 million internal combustion engines each year.[5] Honda became the second-largest Japanese automobile manufacturer in 2001.[6][7] Honda was the eighth largest automobile manufacturer in the world behind General Motors, Volkswagen Group, Toyota, Hyundai Motor Group, Ford, Nissan, and PSA in 2011.[8]
Honda was the first Japanese automobile manufacturer to release a dedicated luxury brand, Acura, in 1986. Aside from their core automobile and motorcycle businesses, Honda also manufactures garden equipment, marine engines, personal watercraft and power generators, amongst others. Since 1986, Honda has been involved with artificial intelligence/robotics research and released their ASIMO robot in 2000. They have also ventured into aerospace with the establishment of GE Honda Aero Engines in 2004 and the Honda HA-420 HondaJet, which began production in 2012. Honda has three joint-ventures in China (Honda China, Dongfeng Honda, and Guangqi Honda).
In 2013, Honda invested about 5.7% (US$ 6.8 billion) of its revenues in research and development.[9] Also in 2013, Honda became the first Japanese automaker to be a net exporter from the United States, exporting 108,705 Honda and Acura models while importing only 88,357</p>
</div>
<div class="clear"></div>
</div>
<div class="grids_of_2 top">
<div class="grid images_3_of_1">
<img src="../images/pic2.jpg">
</div>
<div class="grid span_2_of_3">
<h3>CEO of Honda</h3>
<p class="para">Kawamoto acted quickly to change Honda's corporate culture, rushing through market-driven product development that resulted in recreational vehicles such as the Odyssey[disambiguation needed] and the CR-V, and a refocusing away from some of the numerous sedans and coupes that were popular with Honda's engineers but not with the buying public. The most shocking change to Honda came when Kawamoto ended Honda's successful participation in Formula One after the 1992 season, citing costs in light of the takeover threat from Mitsubishi as well as the desire to create a more environmentally-friendly company image.[21]
Later, 1995 gave rise to the Honda Aircraft Company with the goal of producing jet aircraft under Honda's name</p>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</center>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<div class="footer_bg">
<div class="wrap">
<div class="wrapper">
<div class="footer">
<div class="copy">
<p class="w3-link">© </p>
</div>
<div class="f_nav">
<ul>
<li><a href="#">Skype</a></li>
<li><a href="#">Linked in</a></li>
<li><a href="#">Twitter</a></li>
<li><a href="#">Facebook</a></li>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</body>
</html>
</body>
</html>
非常感谢任何帮助!谢谢!
答案 0 :(得分:0)
这是一个非常糟糕的设计,但我希望,你会得到逻辑。
session_start();
if (!empty($_POST["username"]) && !empty($_POST["password"])) {
//If form has submitted
//Get user from database.
if ($numrows > 0) {
$_SESSION["loggedIn"] = true;
//You can set here more session things, like username, email, etc...
} else {
$_SESSION["loggedIn"] = false;
}
}
if (empty($_SESSION["loggedIn"])) {
//Show content if user is not logged in.
//You can include your file here, when user not logged in
} else {
//Show content if user is logged in.
//You can include your file here
//The best practice, if you are redirect to the user here to another page.
//Do this check in all page, when user needs to be logged in
}
//HTML code comes here.