注册登录php代码,php登录注册源码下载

本文目录一览:

求一用php写的注册和登录页面代码

reg.php文件

?php

header(“Content-type:text/html;charset=utf-8”);

if($_POST){

$dsn = ‘mysql:dbname=1104javab;host=127.0.0.1’;

$user = ‘root’;

$password = ”;

try{

$pdo = new pdo($dsn,$user,$password,array(PDO::MYSQL_ATTR_INIT_COMMAND = ‘SET NAMES \’UTF8\”)

);

}catch(Exception $e){

echo ‘错误’.$e-getmessage();

}

$name = $_POST[‘name’];

$pwd = md5($_POST[‘pwd’]);

$sql = “insert into 表 (username,password) values (‘$name’,’$pwd’)”;

$exec = $pdo-query($sql);

if($exec){

echo “scriptalert(‘成功’);location.href=’reg.html’/script”;

}else{

echo “scriptalert(‘失败’);location.href=’reg.html’/script”;

}

}

?

reg.html文件

form action=’reg.php’ method=’post’

用户名:input type=’text’ name=’name’

密码:input type=’password’ name=’pwd’

input type=’submit’ value=’submit’

/form

login.html文件

form action=’reg.php’ method=’post’

用户名:input type=’text’ name=’name’

密码:input type=’password’ name=’pwd’

input type=’submit’ value=’submit’

/form

login.php文件

header(“Content-type:text/html;charset=utf-8”);

if($_POST){

$dsn = ‘mysql:dbname=1104javab;host=127.0.0.1’;

$user = ‘root’;

$password = ”;

try{

$pdo = new pdo($dsn,$user,$password,array(PDO::MYSQL_ATTR_INIT_COMMAND = ‘SET NAMES \’UTF8\”)

);

}catch(Exception $e){

echo ‘错误’.$e-getmessage();

}

$name = $_POST[‘name’];

$pwd = $_POST[‘pwd’];

$sql = “select user_id from 表名 where username=’$name’ and password=’$pwd'”;

$stmt = $pdo-query($sql);

$info = $stmt-fetch(PDO::FETCH_ASSOC);

if($info){

echo “登录成功”;

}else{

echo “登录失败”;

}

}

大概这样

php写一个登陆注册代码,求大神解答。

index.html 包含注册和登录

!doctype html

html lang=”en”

head

meta charset=”UTF-8″

titleindex/title

style

.x-stage {

margin:50px auto auto;

width:400px;

font-size:12px;

}

.x-head{

font-size:0;

}

.x-tag{

display:inline-block;

vertical-align:middle;

font-size:12px;

font-weight:bold;

color:white;

background-color:gray;

height:30px;

line-height:30px;

text-align:center;

width:200px;

cursor:default;

}

.x-tag.x-active{

background-color:orange;

}

.x-body{

padding:15px 0 0 60px;

}

.x-panel{

display:none;

}

.x-panel.x-active{

display:block;

}

.x-panel label{

display:block;

line-height:30px;

}

.x-panel input{

vertical-align:middle;

}

/style

script

window.onload = function(){

var tags = document.getElementsByClassName(‘x-tag’);

var panels = document.getElementsByClassName(‘x-panel’);

var head = document.getElementsByClassName(‘x-head’)[0];

var lastIdx = 0;

var idx = /(?:^\?|)idx(?:\=)(.*?)(?=|$)/.exec(location.search);

var msg = /(?:^\?|)msg(?:\=)(.*?)(?=|$)/.exec(location.search);

idx = idx  idx[1] || 0;

msg = msg  msg[1] || ”;

var active = function(idx){

if(idx == lastIdx)

return;

tags[lastIdx].className = tags[lastIdx].className.replace(/\sx-active/,”);

panels[lastIdx].className = panels[lastIdx].className.replace(/\sx-active/,”);

tags[idx].className += ‘ x-active’;

panels[idx].className += ‘ x-active’;

lastIdx = idx;

};

head.onclick = function(e){

var el = e.target;

if(!/x-tag/.test(el.className)) return;

for(var i=0,len=tags.length;ilen;i++){

if(el === tags[i]){

active(i);

break;

}

}

};

active(idx);

if(msg) alert(decodeURI(msg));

};

/script

/head

body

div class=”x-stage”

div class=”x-head”

div class=”x-tag x-active”登录/div

div class=”x-tag”注册/div

/div

div class=”x-body”

div class=”x-panel x-active”

form name =”login” action=”response.php” method=”post”

label帐号:/label

input type=”text” name=”usercode” required

label密码:/label

input type=”password” name=”pwd” required

input type=”submit”

input type=”hidden” name=”req-type” value=”login”

/form

/div

div class=”x-panel”

form name = “regist” action=”response.php” method=”post”

label帐号:/label

input type=”text” name=”usercode” required

label密码:/label

input type=”password” name=”pwd” required

label性别:/label

input type=”radio” name=”sex” value=”0″ checked男/input

input type=”radio” name=”sex” value=”1″女/input

label角色:/label

input type=”checkbox” name=”role” value=”0″ checked角色1/input

input type=”checkbox” name=”role” value=”1″角色2/input

input type=”checkbox” name=”role” value=”2″角色3/input

labelE-Mail:/label

input type=”text” name=”email” required

label昵称:/label

input type=”text” name=”nickname” required

label头像:/label

input type=”text” name=”image” required

input type=”submit”

input type=”hidden” name=”req-type” value=”regist”

/form

/div

/div

/div

/body

/html

response.php 包含注册和登录

?php

$dsn = array(‘127.0.0.1’, ‘root’, ‘123456’, ‘bbs’,3306);

// 这里假设表名为user描述里没有说

$query_sql = ‘select `usercode`,`id` from `user` where `usercode` = ? and `pwd` = ?’;

$query_param_types = ‘ss’;

// 这里假设 sex role 是int类型 image是连接地址 也就是varchar类型

$insert_sql = ‘insert into `user`(`usercode`,`pwd`,`sex`,`role`,`email`,`nickname`,`image`) values(?,?,?,?,?,?,?)’;

$insert_param_types =’ssddsss’;

function get_request(){

$params = array();

$type;

$i = 0;

foreach($_REQUEST as $key=$param)

if($key!=’req-type’)

$params[$i++] = $param;

else $type = $param;

return array(

‘params’=$params,

‘type’=$type

);

}

function query($dsn,$sql,$param_types,$params,$fetch = true,$char_set=’UTF8′){

$client = mysqli_init();

call_user_func_array(array($client,’real_connect’),$dsn);

if($char_set) $client-set_charset($char_set);

$stmt = $client-prepare($sql);

foreach($params as $pk=$pv)

$params[$pk] = $params[$pk];

array_unshift($params,$param_types);

$c_stmt = new ReflectionClass(‘mysqli_stmt’);

$cm_stmt = $c_stmt-getMethod(‘bind_param’);

$cm_stmt-invokeArgs($stmt,$params);

$stmt-execute();

if(!$fetch){

$affected_rows = $stmt-affected_rows;

$client-close();

return $affected_rows;

}

$result = $stmt-get_result();

$set = array();

while($row = $result-fetch_array(MYSQL_ASSOC))

$set[]=$row;

$result-free();

$client-close();

return $set;

}

$request = get_request();

$msg = ‘请求类别错误!’;

$idx = 0;

$result = null;

if($request[‘type’] == ‘login’){

$idx = 0;

$result = query($dsn,$query_sql,$query_param_types,$request[‘params’]);

$msg = empty($result) ? ‘用户名或密码错误!’ : ‘登录成功!’;

}

if($request[‘type’] == ‘regist’){

$idx =1;

$result = query($dsn,$insert_sql,$insert_param_types,$request[‘params’],false);

if(empty($result)){

$msg = ‘注册失败!’;

$idx = 1;

}else {

$msg = ‘注册成功!’;

$idx = 0;

}

}

header(‘location:index.html?msg=’.$msg.’idx=’.$idx);

求一个简单的PHP注册,登陆代码

我帮你找了个小程序

程序介绍:

1、共4个页面,conn.php连接数据库、img.php图片验证码、index.php登录页面、register.php注册页面

2、注册页面全是用js来验证的,所以不太完善,后续会改进

3、还没有学习ajax,所以图片没法点击刷新。原谅我吧

4、每段代码都含有详细注释,方便交流学习

程序使用:

1、下载源码上传到你网站某个目录

2、打开你的数据库,在某个表中执行readme.txt中的SQL语句创建字段用来存放用户数据

3、修改conn.php填写对应的数据库地址、用户名、密码、数据表

4、确保上述操作无误后,打卡URL地址进行测试

源码git地址

php注册功能代码

注册页面表单提交时没有提交sex字段,$_SESSION[‘sname’]没有赋值,可以直接在前面加上error_reporting(E_ALL^E_NOTICE),防止NOTICE报出

原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/200100.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
小蓝的头像小蓝
上一篇 2024-12-05 14:03
下一篇 2024-12-05 14:03

相关推荐

  • Python周杰伦代码用法介绍

    本文将从多个方面对Python周杰伦代码进行详细的阐述。 一、代码介绍 from urllib.request import urlopen from bs4 import Bea…

    编程 2025-04-29
  • Python字符串宽度不限制怎么打代码

    本文将为大家详细介绍Python字符串宽度不限制时如何打代码的几个方面。 一、保持代码风格的统一 在Python字符串宽度不限制的情况下,我们可以写出很长很长的一行代码。但是,为了…

    编程 2025-04-29
  • PHP和Python哪个好找工作?

    PHP和Python都是非常流行的编程语言,它们被广泛应用于不同领域的开发中。但是,在考虑择业方向的时候,很多人都会有一个问题:PHP和Python哪个好找工作?这篇文章将从多个方…

    编程 2025-04-29
  • Python基础代码用法介绍

    本文将从多个方面对Python基础代码进行解析和详细阐述,力求让读者深刻理解Python基础代码。通过本文的学习,相信大家对Python的学习和应用会更加轻松和高效。 一、变量和数…

    编程 2025-04-29
  • Python满天星代码:让编程变得更加简单

    本文将从多个方面详细阐述Python满天星代码,为大家介绍它的优点以及如何在编程中使用。无论是刚刚接触编程还是资深程序员,都能从中获得一定的收获。 一、简介 Python满天星代码…

    编程 2025-04-29
  • 仓库管理系统代码设计Python

    这篇文章将详细探讨如何设计一个基于Python的仓库管理系统。 一、基本需求 在着手设计之前,我们首先需要确定仓库管理系统的基本需求。 我们可以将需求分为以下几个方面: 1、库存管…

    编程 2025-04-29
  • 写代码新手教程

    本文将从语言选择、学习方法、编码规范以及常见问题解答等多个方面,为编程新手提供实用、简明的教程。 一、语言选择 作为编程新手,选择一门编程语言是很关键的一步。以下是几个有代表性的编…

    编程 2025-04-29
  • Python实现简易心形代码

    在这个文章中,我们将会介绍如何用Python语言编写一个非常简单的代码来生成一个心形图案。我们将会从安装Python开始介绍,逐步深入了解如何实现这一任务。 一、安装Python …

    编程 2025-04-29
  • 怎么写不影响Python运行的长段代码

    在Python编程的过程中,我们不可避免地需要编写一些长段代码,包括函数、类、复杂的控制语句等等。在编写这些代码时,我们需要考虑代码可读性、易用性以及对Python运行性能的影响。…

    编程 2025-04-29
  • Python爱心代码动态

    本文将从多个方面详细阐述Python爱心代码动态,包括实现基本原理、应用场景、代码示例等。 一、实现基本原理 Python爱心代码动态使用turtle模块实现。在绘制一个心形的基础…

    编程 2025-04-29

发表回复

登录后才能评论