index.php
login.html
1
2
3
4
5
6
7
8
9
10
11
12
|
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<?php
session_start();
if
(isset(
$_SESSION
[
"name"
])&&time()>
$_SESSION
[
'name'
] + 1200){
echo
"<hr>"
;
echo
$_SESSION
[
'name'
];
echo
"<hr>"
;
echo
"welcome back"
;
}
else
echo
"<script>alert('先登陆。。。!');location.href='login.html';;</script>"
;
?>
|
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<?php
session_start();
$conn
=mysql_connect(
"localhost"
,
"root"
,
""
);
if
(!
$conn
)
{
die
(
'Could not connect: '
. mysql_error());
}
$userName
=
$_POST
[
'userName'
];
$userPwd
=
$_POST
[
'userPwd'
];
//$userPwd=md5(trim($_POST['userPwd']));
mysql_select_db(mydb,
$conn
);
$sql
=
"SELECT * FROM TABLES where username='"
.
$userName
.
"' and password='"
.
$userPwd
.
"'"
;
$rows
=mysql_fetch_array( mysql_query(
$sql
));
echo
$sql
;
if
(
empty
(
$userName
)){
echo
"用户名NULL"
;
}
else
if
(
empty
(
$userPwd
)){
echo
"密码NULL"
;
}
else
{
if
(
$rows
[
'password'
]==
$userPwd
)
{
echo
"<script>alert('登陆成功。。。!');location.href='index.php';;</script>"
;
$_SESSION
[
'name'
]=
$userName
;
}
else
{
echo
"<script>alert('用户名或密码错误!!!!');history.back();</script>"
;
}
}
mysql_close(
$conn
);
?>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<!
DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
>
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=utf-8"
/>
<
title
>无标题文档</
title
>
</
head
>
<
body
>
<
form
name
=
"login"
method
=
"POST"
action
=
"login.php"
>
<
fieldset
style
=
"color:blue;;position:absolute;top:20%;left:35%"
>
<
legend
>登录</
legend
>
<
p
>用户名 <
input
type
=
"text"
name
=
"userName"
id
=
"userName"
/></
p
>
<
p
>密 码 <
input
type
=
"password"
name
=
"userPwd"
id
=
"userPwd"
/></
p
>
<
p
>
<
input
type
=
"submit"
value
=
"登录"
style
=
"color:blue"
/>
<
input
type
=
"reset"
value
=
"重置"
style
=
"color:blue"
/>
</
fieldset
>
</
form
>
</
body
>
</
html
>
|