代码练习 用户注册登陆与密码加密
生活随笔
收集整理的這篇文章主要介紹了
代码练习 用户注册登陆与密码加密
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
reg.html
<html><head><title>注冊</title><meta http-equiv="cotent-type" content="text/html;charset=utf-8"></head><body><form action="doaction.php?act=reg" method="post">請填寫用戶名:<input type="text" name="username"><br><br>密碼:<input type="password" name="password"><br><br><input type="submit" value="注冊"></form></body> </html>login.php
<head><title>用戶登陸</title></head><body><form action="doaction.php?act=log" method="post">用戶名:<input type="text" name="name">密碼:<input type="password" name="pwd"><input type="submit" value="log"></form></body> </html>doaction.php
<?php header('content-type:text/html;charset=utf-8'); session_start(); $act=$_REQUEST['act']; if($act=='reg'){//接收參數$name=$_POST['username'];$pwd=md5(md5($_POST['password']));//注冊if($name!==null){if ($pwd!==null) {//鏈接數據庫$conn=new mysqli('localhost','root','123','users');if(mysqli_connect_errno()){$error=mysqli_connect_errno();$errmsg=mysqli_connect_error();echo "鏈接不成功:($errno)$errmsg<br/>";$conn->close();exit;}else{//echo "鏈接成功";$conn->query("set names utf-8");$sql="insert into user(name,pwd) values('{$name}','{$pwd}')";$result=@$conn->query($sql);//echo $sql;exit;if(@$result){echo '注冊成功,歡迎你'.$name;}else{echo '注冊失敗';}}# code...}else{exit('請填寫密碼');}}else{exit('請填寫用戶名');}}elseif($act=='log'){$name=$_POST['name'];$pwd=$_POST['pwd'];if($name!==null){if($pwd!==null){$conn=new mysqli('localhost','root','123','users');$sql="select name,pwd from user where name='$name' and pwd='$pwd'";$result=$conn->query($sql);if($result){echo "登陸成功,歡迎回來".$name;}else{echo "登錄失敗";exit;}}}}?$_GET變量接受所有以get方式發送的請求,及瀏覽器地址欄中的?之后的內容
$_POST變量接受所有以post方式發送的請求,例如,一個form以method=post提交,提交后php會處理post過來的全部變量
而$_REQUEST支持兩種方式發送過來的請求,即post和get它都可以接受,顯示不顯示要看傳遞方法,get會顯示在url中(有字符數限制),post不會在url中顯示,可以傳遞任意多的數據(只要服務器支持)
轉載于:https://www.cnblogs.com/perseverancevictory/p/4291146.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的代码练习 用户注册登陆与密码加密的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sama5d3 xplained 系统加
- 下一篇: 表视图