phpログインバックグラウンド検証コード
2903 ワード
フロントフォーム:
バックグラウンドログイン認証コード:
PHPプロジェクトでは、セッションを利用して各ページにログイン検証を行います.
checklogin2.php
他のPHPファイルでは、上のログイン検証ファイルを呼び出します.形式は以下の通りです.
<span style="font-size:18px;"><span style="font-size:18px;"><form action="check_login.php" name="loginform" method="post">
:
<input type="text" name="name" />
:
<input type="password" name="pwd" />
<input type="submit" value=" " />
</form></span></span>
バックグラウンドログイン認証コード:
<span style="font-size:18px;"><span style="font-size:18px;"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8" />
</head>
<?php
session_start(); // session
$username = $_POST['name']; //
$password=md5($_POST['pwd']); //
class chkinput //
{
var $name;
var $pwd;
function chkinput($x,$y) //
{
$this->name=$x; // $this->name
$this->pwd=$y; // $this->pwd
}
function checkinput()
{
include("conn.php"); //
$sql=mysql_query("select username,password from admin where username='".$this->name."' and password='".$this->pwd."'",$conn);
$info=mysql_fetch_array($sql); //
if($info==false) // ,
{
echo "<script language='javascript'>alert(' , !');history.back();</script>";
exit;
}
else // ,
{
echo "<script>window.location='home.php';</script>";
$_SESSION['admin_name']=$info['username']; // $_SESSION[admin_name]
$_SESSION['pwd']=$info['password']; //// $_SESSION[pwd]
}
}
}
$obj=new chkinput(trim($username),trim($password)); //
$obj->checkinput(); //
?>
</html></span></span>
PHPプロジェクトでは、セッションを利用して各ページにログイン検証を行います.
checklogin2.php
<span style="font-size:18px;"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8" />
</head>
<?php error_reporting(E_ALL^E_NOTICE); // NOTICE ?>
<?php
session_start();
// , , 。
if($_SESSION["admin_name"] == "")
{
echo "<script>alert(' , !');window.location.href='index.html';</script>";
}
?>
</html></span>
他のPHPファイルでは、上のログイン検証ファイルを呼び出します.形式は以下の通りです.