首页技术php做一个登陆页面 php和HTML做登录页面

php做一个登陆页面 php和HTML做登录页面

编程之家2026-06-131051次浏览

这篇文章给大家聊聊关于php做一个登陆页面,以及php和HTML做登录页面对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。

php做一个登陆页面 php和HTML做登录页面

如何用php做出登陆注册留言板

登录页:login.php

<?php

include("conn.php");

$username=$_POST['name'];

$password=$_POST['password'];

$yanzheng=$_POST['yanzheng'];

php做一个登陆页面 php和HTML做登录页面

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)

php做一个登陆页面 php和HTML做登录页面

{

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>

<td><input type="text" name="name" id="name"/></td>

</tr>

<tr>

<td>用户密码:</td>

<td><input type="password" name="password" id="password"/></td>

</tr>

<tr>

<td>验证码:</td>

<td><input 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 rel="external nofollow" 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 rel="external nofollow" rel="external nofollow" href="login.php">返回登录页</a>]</td>

</tr>

<tr>

<td height=40 bgColor=#fffbec>会员ID</td>

<td><input type="text" name="username" id="username"/></td>

</tr>

<tr>

<td height=40 bgColor=#fffbec>密码</td>

<td><input 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=#fffbec>EMAIL</td>

<td><input type="text" name="email" id="email"/>

</tr>

<tr>

<td height=40 bgColor=#fffbec></td>

<td><input 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; i<aa.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; i<aa.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=3><a rel="external nofollow" rel="external nofollow" href="login.php" style="float:right">[退出系统]</a><a rel="external nofollow" 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($num>0)

{

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

?>

<tr align=middle>

<td bgColor=#fffbec><input type="checkbox" name="selected" value="1"/></td>

<td height=50 bgColor=#fffbec width=300>

<?php

echo"<div><a 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=#fffbec><div><?php echo$row['last_post_time']."by".$row['last_post_author']?></div></td>

</tr>

<?php

}

}

else

{

echo"<tr bgColor=#fffbec><td colspan=3>对不起,论坛尚在创建中……</td></tr>";

}

?>

<tr>

<td colspan=3><input type="checkbox" name="selected" value="1" onclick="All(this,'selected')"/>全选/不全选</td>

</tr>

<tr>

<td><input type="button" name="del" id="del" value="删除选中项"/>

<?php

?>

</td>

</tr>

</table>

</html>

自己创建数据库就好。

用PHP做网站后台管理登陆界面详细代码

给你点思路,若是不懂的话你可以hi我。

第一步、新建一个form表单,用来提交用户名及密码

(action属性为你需要把数据提交到哪个页面。method属性为你的提交方式,这里使用post,下面两个input文本框一个是用户名,一个为密码。)

第二步、数据处理页面,使用传过来的值在数据表里面查询,看看是否有这条数据,若是没有就提示登录失败,若是有这条数据就把用户名存储到session里面,然后在index.html页面判断有没有session,若是有session的话就进入到index.html页面。

php封装一个用户类,里面有登录注册方法,这个要怎么写

第一步:login.php

//登陆方法

public function login(){

//如果用户名和密码为空,则返回登陆页面

if(empty($_POST['username'])|| empty($_POST['password'])){

$data['verifycode']= rand(1000,9999);//生成一个四位数字的验证码

//将验证码放入session中,注意:参数是数组的格式

$this->session->set_userdata($data);

//注意:CI框架默认模板引擎解析的模板文件中变量不需要$符号

//$this->parser->parse("admin/login",$data);

//smarty模板变量赋值

$this->tp->assign("verifycode",$data['verifycode']);

//ci框架在模板文件中使用原生态的PHP语法输出数据

//$this->load->view('login',$data);//登陆页面,注意:参数2需要以数组的形式出现

//显示smarty模板引擎设定的模板文件

$this->tp->display("admin/login.php");

}else{

$username= isset($_POST['username'])&&!empty($_POST['username'])?trim($_POST['username']):'';//用户名

$password= isset($_POST['password'])&&!empty($_POST['password'])?trim($_POST['password']):'';//密码

$verifycode= isset($_POST['verifycode'])&&!empty($_POST['verifycode'])?trim($_POST['verifycode']):'';//验证码

//做验证码的校验

if($verifycode==$this->session->userdata('verifycode')){

//根据用户名及密码获取用户信息,注意:参数2是加密的密码

$user_info=$this->user_model->check_user_login($username,md5($password));

if($user_info['user_id']> 0){

//将用户id、username、password放入cookie中

//第一种设置cookie的方式:采用php原生态的方法设置的cookie的值

//setcookie("user_id",$user_info['user_id'],86500);

//setcookie("username",$user_info['username'],86500);

//setcookie("password",$user_info['password'],86500);

//echo$_COOKIE['username'];

//第二种设置cookie的方式:通过CI框架的input类库

$this->input->set_cookie("username",$user_info['username'],3600);

$this->input->set_cookie("password",$user_info['password'],3600);

$this->input->set_cookie("user_id",$user_info['user_id'],3600);

//echo$this->input->cookie("password");//适用于控制器

//echo$this->input->cookie("username");//适用于控制器

//echo$_COOKIE['username'];//在模型类中可以通过这种方式获取cookie值

//echo$_COOKIE['password'];//在模型类中可以通过这种方式获取cookie值

//第三种设置cookie的方式:通过CI框架的cookie_helper.php函数库文件

//这种方式不是很灵验,建议大家采取第二种方式即可

//set_cookie("username",$user_info['username'],3600);

//echo get_cookie("username");

//session登陆时使用:将用户名和用户id存入session中

//$data['username']=$user_info['username'];

//$data['user_id']=$user_info['user_id'];

//$this->session->set_userdata($data);

//跳转到指定页面

//注意:site_url()与base_url()的区别,前者带index.php,后者不带index.php

header("location:".site_url("index/index"));

}

}else{

//跳转到登陆页面

header("location:".site_url("common/login"));

}

}

}

}

第二步:User_model.php

//cookie登陆:检测用户是否登陆,如果cookie值失效,则返回false,如果cookie值未失效,则根据cookie中的用户名和密码从数据库中获取用户信息,如果能获取到用户信息,则返回查询到的用户信息,如果没有查询到用户信息,则返回0

public function is_login(){

//获取cookie中的值

if(empty($_COOKIE['username'])|| empty($_COOKIE['password'])){

$user_info= false;

}else{

$user_info=$this->check_user_login($_COOKIE['username'],$_COOKIE['password']);

}

return$user_info;

}

//根据用户名及加密密码从数据库中获取用户信息,如果能获取到,则返回获取到的用户信息,否则返回false,注意:密码为加密密码

public function check_user_login($username,$password){

//这里大家要注意:$password为md5加密后的密码

//$this->db->query("select* from");

//快捷查询类的使用:能为我们提供快速获取数据的方法

//此数组为查询条件

//注意:关联数组

$arr=array(

'username'=>$username,//用户名

'password'=>$password,//加密密码

'status'=>1//账户为开启状态

);

//在database.php文件中已经设置了数据表的前缀,所以此时数据表无需带前缀

$query=$this->db->get_where("users",$arr);

//返回二维数组

//$data=$query->result_array();

//返回一维数组

$user_info=$query->row_array();

if(!empty($user_info)){

return$user_info;

}else{

return false;

}

}

第三步:其它控制器:

public function __construct(){

//调用父类的构造函数

parent::__construct();

$this->load->library('tp');//smarty模板解析类

$this->load->helper('url');//url函数库文件

$this->load->model("user_model");//User_model模型类实例化对象

$this->cur_user=$this->user_model->is_login();

if($this->cur_user=== false){

header("location:".site_url("common/login"));

}else{

//如果已经登陆,则重新设置cookie的有效期

$this->input->set_cookie("username",$this->cur_user['username'],3600);

$this->input->set_cookie("password",$this->cur_user['password'],3600);

$this->input->set_cookie("user_id",$this->cur_user['user_id'],3600);

}

$this->load->library('pagination');//分页类库

$this->load->model("role_model");//member_model模型类

$this->load->model("operation_model");//引用operation_model模型

$this->load->model("object_model");//引用object_model模型

$this->load->model("permission_model");//引用permission_model模型

}

关于本次php做一个登陆页面和php和HTML做登录页面的问题分享到这里就结束了,如果解决了您的问题,我们非常高兴。

任意三角函数的计算方法(三角形斜边计算器)今年万圣节是什么时候(2021年万圣节啥时候)