本文目录一览:
- 1、如何用php制作登陆页面
- 2、用PHP做登陆注册页面
- 3、PHP做一个用户登录页面
- 4、PHP制作登录页面
- 5、如何制作php登陆界面
- 6、php登陆页面完整代码
如何用php制作登陆页面
在login.php那里,在$_SESSION['username']=$username;后面加 $_SESSION['Aname']=$row['Aname'];
check.php则改成
?php
session_start();
$Aname=@$_SESSION['Aname'];
if ($Aname)
{
echo"欢迎您".$Aname."!";
}
else
echo "script language='javascript'alert('您没有权限查看!');location='login.php';/script";
?
是否可以解决您的问题?
用PHP做登陆注册页面
登录页:login.php
?php
include("conn.php");
$username=$_POST['name'];
$password=$_POST['password'];
$yanzheng=$_POST['yanzheng'];
if(isset($_POST['submit']))
{
$sql=("select username,password from member where username='$username' and password='$password'") or die("sql语句执行失败");
//print_r($sql);
$ar=mysql_query($sql);
if($ar)
{
if($row=mysql_fetch_array($ar))
{
session_start();
if($_POST["yanzheng"])
{
if($yanzheng!=$_session[pic]||$yanzheng=="")
{
echo "验证码输入有误";
exit;
}
if($yanzheng==$_session[pic])
{
header("location:index.php");
}
}
}
else
{
echo "用户名或密码错误";
}
}
}
?
form action="login.php" method="post"
table border=1 align=center width=500 height=300 bgColor=#DFFFDF bordercolor=#fffbec
tr
td colspan=2 align=center用户登录/td
/tr
tr
td用户姓名:/td
tdinput type="text" name="name" id="name"//td
/tr
tr
td用户密码:/td
tdinput type="password" name="password" id="password"//td
/tr
tr
td验证码:/td
tdinput type="text" name="yanzheng" id="yanzheng"/
img src="yanzheng1.php" width="50" height="30"/img
/td
/tr
tr
td colspan=3 align=center
input type="submit" name="submit" value="登录"/
input type="reset" name="reset" value="重置"/
a href="register.php"注册/a
/td
/tr
/table
/form
注册页:register.php
?php
include("conn.php");
if(isset($_POST['submit'])$_POST['submit']) {
if($_POST['username']=='')
{
echo "用户名不能为空";
exit();
}
if($_POST['password']=='')
{
echo "密码不能为空";
exit();
}
if($_POST['realpass']!=$_POST['password'])
{
echo "两次密码输入不一致";
exit();
}
$sql="insert into member(username,real_name,password,email,headimg) values('$_POST[username]','$_POST[username]','$_POST[password]','$_POST[email]','')";
$ar=mysql_query($sql);
if($ar)
{
header("location:index.php");
}
else
{
echo mysql_error();
}
}
?
body
form action="register.php" method="post"
table border=1 align=center width=500
tr
td height=40 bgColor=#DFFFDF colspan=2会员注册 [a href="login.php"返回登录页/a]/td
/tr
tr
td height=40 bgColor=#fffbec 会员ID/td
tdinput type="text" name="username" id="username"//td
/tr
tr
td height=40 bgColor=#fffbec密码/td
tdinput type="password" name="password" id="password"//td
/tr
tr
td height=40 bgColor=#fffbec确认密码/td
td
input type="password" name="realpass" id="realpass"/
/td
/tr
tr
td height=40 bgColor=#fffbecEMAIL/td
tdinput type="text" name="email" id="email"/
/tr
tr
td height=40 bgColor=#fffbec/td
tdinput type="submit" name="submit" value="注册"/input type="reset" value="重置"/td
/tr
/table
/form
/body
主页显示:index.php
?php
include("conn.php");
function cutstr($str,$cutleng)
{
$str = $str; //要截取的字符串
$cutleng = $cutleng; //要截取的长度
$strleng = strlen($str); //字符串长度
if($cutleng$strleng)return $str;//字符串长度小于规定字数时,返回字符串本身
$notchinanum = 0; //初始不是汉字的字符数
for($i=0;$i$cutleng;$i++)
{
if(ord(substr($str,$i,1))=128)
{
$notchinanum++;
}
}
if(($cutleng%2==1)($notchinanum%2==0)) //如果要截取奇数个字符,所要截取长度范围内的字符必须含奇数个非汉字,否则截取的长度加一
{
$cutleng++;
}
if(($cutleng%2==0)($notchinanum%2==1)) //如果要截取偶数个字符,所要截取长度范围内的字符必须含偶数个非汉字,否则截取的长度加一
{
$cutleng++;
}
return substr($str,0,$cutleng);
}
?
html
head
script type="text/javascript"
function All(e, itemName)
{
var aa = document.getElementsByName(itemName);
for (var i=0; iaa.length; i++)
aa[i].checked = e.checked; //得到那个总控的复选框的选中状态
}
function Item(e, allName)
{
var all = document.getElementsByName(allName)[0];
if(!e.checked) all.checked = false;
else
{
var aa = document.getElementsByName(e.name);
for (var i=0; iaa.length; i++)
if(!aa[i].checked) return;
all.checked = true;
}
}
/script
/head
?php
include("conn.php");
if(isset($_POST['del']))
{
$mm = $_POST["selected"];
$id =implode(",",$mm);
$sql = "delete from forums where id in(".$id.")";
//echo $sql;
$result=mysql_query($sql);
echo $result?"删除成功":"删除失败";
}
?
table style="BORDER-BOTTOM-WIDTH: 1px; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=600 align=center border=1 bordercolor=#ddddff
tr align=middle
td height=40 bgColor=#DFFFDF colspan=3论坛列表/td
/tr
tr
td colspan=3a href="login.php" style="float:right"[退出系统]/aa href="add_forum.php" style="float:right"[添加论坛]/a/td
td/td
/tr
tr align=middle
td height=40 bgColor=#DFFFDF width=80状态/td
td height=40 bgColor=#DFFFDF论坛/td
td height=40 bgColor=#DFFFDF最后更新/td
/tr
?php
$sql="select * from forums";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($num0)
{
while($row=mysql_fetch_array($result)){
?
tr align=middle
td bgColor=#fffbecinput type="checkbox" name="selected" value="1"//td
td height=50 bgColor=#fffbec width=300
?php
echo "diva href="forums.php?F=".$row['ID'].""".$row['forum_name']."/a/div";
echo cutstr($row['forum_description'],24);//最多显示24个字节,12个字,多余部分用省略号代替
echo "……";
?
/td
td height=50 bgColor=#fffbecdiv?php echo $row['last_post_time']."by".$row['last_post_author']?/div/td
/tr
?php
}
}
else
{
echo "tr bgColor=#fffbectd colspan=3对不起,论坛尚在创建中……/td/tr";
}
?
tr
td colspan=3 input type="checkbox" name="selected" value="1" onclick="All(this,'selected')"/全选/不全选/td
/tr
tr
tdinput type="button" name="del" id="del" value="删除选中项"/
?php
?
/td
/tr
/table
/html
数据库你就自己建,望采纳~
PHP做一个用户登录页面
index.html登录页面代码如下:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312" /
title登录示例/title
/head
body
form id="forms" name="forms" method="post" action="loginchk.php"
用户名:input type="text" id="uname" name="uname" value=""/br/
密码:input type="password" id="upass" name="upass" value=""/br/
input type="submit" id="loginbtn" value="立即登录"/
input type="reset" id="resetbtn" value="重新填写"/
/form
/body
/html
loginchk.php 的PHP程序代码如下:
?php
$uname=trim($_REQUEST["uname"]);
$upass=trim($_REQUEST["upass"]);
if($uname=="admin"$upass=="admin")
{
echo "登录成功";
}
else
{
echo "登录失败,a href='index.html'重新登录/a";
}
?
以上只是一个简单示例,真正的开始,需要考到很多因素,比如说登录前有效性检查,加入登录验证码,程序需要连接数据库进行用户匹配等。
希望对你有帮助 。
如果使用数据库进行进行匹配的话,PHP程序可以这样改进一下。
?php
$uname=trim($_REQUEST["uname"]);
$upass=trim($_REQUEST["upass"]);
$con = mysql_connect("localhost","root","root");
mysql_select_db("dbname", $con);
$result = mysql_query("select * from dusers where uname='$uname' and upass='$upass'");
$rs = mysql_fetch_array($result);
if($rs)
{
echo "登录成功";
}
else
{
echo "登录失败,a href='index.html'重新登录/a";
}
?
不过你需要连接到你自己的指定的数据库和数据表。
PHP制作登录页面
准简单的登录页面
?php
if(isset($_POST['username']) isset($_POST['password'])){
$u = $_POST['username'];
$p = $_POST['password'];
//此处可进行用户名密码检测操作
if($u == 'admin' $p == '123456'){
echo '登录成功';
//此处可进行登录成功操作
}else{
echo '登录失败';
//此处可进行登录失败操作
}
}
?
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
titleLogin Page/title
/head
body
form action="" method="post"
input name="username" type="text" /
input name="password" type="text" /
/form
/body
/html
如何制作php登陆界面
如果你要的只是界面,那么我给你一个好的建议。
你可以去Bootstrap官网这个里面去找你想要的组件。
做出很炫的登录界面。
并且提供源代码。
凡事多动手,不要只会照搬。
我给你源代码你也不会做。
所以,你还是多去看看如何写。
如果,你要的是源码,那么你也可以去thinkphp官网去看看。有很多很不错的代码。值得学习。登录界面其实很简单,说白了,就是表单提交。
php登陆页面完整代码
PHP登陆后跳转到登陆前页面,利用$_SERVER全局变量可以实现这个功能,下面有个不错的示例,希望对大家有所帮助
最近手上一个小项目让我接触到PHP编程,简单的登陆功能已经OK。可是在实际使用的时候发现一个问题:用户A发送一个链接给用户B,B打开时页面提示登陆,可是登陆成功后,却跳转到了首页,而并不是A发送的链接。为了有更好的用户体验,B登陆成功后应该自动跳转到登陆前的链接。查了PHP帮助手册,利用$_SERVER全局变量可以实现这个功能。 $_SERVER是PHP的一个超全局变量,关于$_SERVER变量的详细解释可以参考: 具体实现方法为:在提示用户登录的同时,在session或者cookie中记录下请求页面的URL;登录验证成功后在跳转回该URL。 checklogin.php 代码如下: session_start(); if (!isset ($_SESSION['login_ok'])) { echo "script language=javascriptalert ('要访问的页面需要先登录。');/script"; $_SESSION['userurl'] = $_SERVER['REQUEST_URI']; echo 'script language=javascriptwindow.location.href="login.php"/script'; } login.php 代码如下: session_start(); //此处省略了账号密码验证代码,验证OK再执行下面代码 if (isset ($_SESSION['userurl'])) { //会话中有要跳转的页面 $url = $_SESSION['userurl']; } else { //没有要跳转的页面,则转到首页 $url = "home.php"; } //0.5s后跳转 echo "meta http-equiv="refresh" content="0.5;url=$url"";