註冊登錄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/zh-tw/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

發表回復

登錄後才能評論