登录(Login.php)

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php //php框架


  session_Start();
  $username=$_REQUEST["username"];  //获取传递信息 id=username
  $password=$_REQUEST["password"];

  $con=mysql_connect("severname","username","password"); //连接数据库 ps:不建议使用此方法 请加密
  if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("UserMDF",$con); //选择表
  $db_username=null;
  $db_password=null;
  $result=mysql_query("select * from Web where Name = '{$username}' "); //数据库语法 select* 选择所有 from user 来自user表  where 条件等于username

  while($Find=mysql_fetch_array($result))  //循环查找
  {
  $db_username=$Find["Name"];     //查找结果并赋值
  $db_password=$Find["Password"];
  }
  if(is_null($db_username)){

  echo $username,$password;
  echo $db_password,$db_username;

?>

<script type="text/javascript">  //javascript框架

  alert("该账号未注册!"); //Js弹出对话框
  document.location.href="index.html"; //返回主页

</script>

<?php  //php框架  承接上一个if语句
  }
  else
  {
    if ($db_password!=$password){

?>

<script type="text/javascript" charset="utf-8">  //javascript框架

  alert("密码错误!"); //Js弹出对话框
  document.location.href="index.html"; //返回主页

</script>

<?php  //php框架  承接上一个if语句
  }
  else
  {
    $_SESSION["username"]=$username;
    $_SESSION["code"]=mt_rand(0,100000); //随机值函数 给code随机赋值 在登录成功后验证  防止通过网址绕过登录

?>

<script type="text/javascript">  //javascript框架

  document.location.href="LoginSuccess.php"; //登录成功

</script>

<?php

}
}
mysql_close($con); //关闭数据库连接

?>

登录成功(LoginSuccess.php)

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
  header("content_type:text/html; charset = utf_8");
  session_Start();
  if(isset($_SESSION["code"]))  //判断code是否存在 存在则返回true
  {

?>

<br>

登录成功!
<br>
您好!
<?php

  echo $_SESSION["username"];

?>
<br>

  <a href="exit.php">退出登录</a>


<br>
<a href="Kamakoto.html">点击跳转主页</a>
<?php

}else{


?>

<script type="text/javascript">
  alert("请勿绕开登录程序!");
  document.location.href="exit.php";
</script>

<?php
}
?>

注册(Reg.php)

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


  <?php
session_Start();
$username=$_REQUEST["username"];
$password=$_REQUEST["password"];
$isOK=true;
if($username==null){
  $isOK=false;
  ?>
<script type="text/javascript">
alert("邮件格式不正确:01");
window.location.href="Reg.html";
</script>
<?php
}
$rule='/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9{2,4}])+$/';
if(!preg_match($rule,$username)){
    $isOK=false;
  ?>
<script type="text/javascript">
alert("邮件格式不正确:02");
window.location.href="Reg.html";
</script>
<?php
}
if($password==null){
    $isOK=false;
  ?>
<script type="text/javascript">
alert("密码格式不正确:03");
window.location.href="Reg.html";
</script>
<?php
}
$con=mysql_connect("server","user","password");
if(!$con){
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("UserMDF",$con);
$db_username=null;
$db_password=null;
$result=mysql_query("select * from Web where Name = '{$username}' ");

while ($Find=mysql_fetch_array($result)) {

$db_username=$Find["Name"];
$db_password=$Find["Password"];

}
if(!is_null($db_username)){
    $isOK=false;
   ?>
<script type="text/javascript">
alert("用户已存在:04");
window.location.href="Reg.html";
</script>
<?php
}
if($isOK==true){
mysql_query("insert into Web(Name,Password) value ('{$username}','{$password}')")or die("注册失败:05".mysql_error());
mysql_close($con);
}
 ?>
 <script type="text/javascript">
  alert("注册成功");
  window.location.href="index.html";
</script>

退出登录(exit.php)

<?php

  session_Start();
  session_destroy(); //销毁SESSION

?>

<script type="text/javascript">

    document.location.href="index.html";

</script>

Per Aspera Ad Astra