php 注冊(cè)時(shí)輸入信息驗(yàn)證器的實(shí)現(xiàn)詳解(2)_PHP教程
推薦:PHP 安全檢測(cè)代碼片段(分享)本篇文章是對(duì)PHP安全檢測(cè)代碼的片段進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下 復(fù)制代碼 代碼如下: /** * html轉(zhuǎn)換輸出(只轉(zhuǎn)義' 保留Html正常運(yùn)行) * @param $param * @return string */ function htmlEscape($param) { return trim(htmlspecialchars($param, ENT_QUOTES
2、在注冊(cè)頁(yè)面進(jìn)行調(diào)用
$username = null;
$password = null;
$repeat_password = null;
$email = null;
$msg = "";
if (isset($_POST['username']) && isset($_POST['password'])
&& isset($_POST['repeat_password']) && isset($_POST['email'])) {
$username = addslashes(trim(stripslashes($_POST ['username'])));
$password = addslashes(trim(stripslashes($_POST ['password'])));
$repeat_password = addslashes(trim(stripslashes($_POST ['repeat_password'])));
$email = addslashes(trim(stripslashes($_POST ['email'])));
// validate
$errors = RegisterValidator::validate($username, $password, $repeat_password, $email);
// validate
if (empty($errors)) {
// save
$dao = new UserDao();
$user = new User();
$user->setEmail($email);
$last_login_ip = Utils::getIpAddress();
$user->setLastLoginIp($last_login_ip);
$user->setUsername($username);
$salt = substr(sha1(mt_rand()), 0, 22);
$hash_password = sha1($salt . $password);
$user->setPassword($hash_password);
$user->setSalt($salt);
$user = $dao->save($user);
if ($user) {
UserLogin::setUserInfo($user);
Flash::addFlash('注冊(cè)成功!');
}
else {
Flash::addFlash('對(duì)不起,由于服務(wù)器內(nèi)部錯(cuò)誤,導(dǎo)致注冊(cè)失敗。請(qǐng)稍后再試。');
}
Utils::redirect('welcome');
}
foreach ($errors as $e) {
$msg .= $e->getMessage()."<br>";
}
3.代碼中Error類(lèi)用于記錄驗(yàn)證時(shí)的錯(cuò)誤信息
<?php
/**
* Validation error.
*/
final class Error {
private $source;
private $message;
/**
* Create new error.
* @param mixed $source source of the error
* @param string $message error message
*/
function __construct($source, $message) {
$this->source = $source;
$this->message = $message;
}
/**
* Get source of the error.
* @return mixed source of the error
*/
public function getSource() {
return $this->source;
}
/**
* Get error message.
* @return string error message
*/
public function getMessage() {
return $this->message;
}
}
?>
分享:php解析html類(lèi)庫(kù)simple_html_dom(詳細(xì)介紹)一直以來(lái)使用php解析html文檔樹(shù)都是一個(gè)難題。Simple HTML DOM parser 幫我們很好地解決了這個(gè)問(wèn)題�?梢酝ㄟ^(guò)這個(gè)php類(lèi)來(lái)解析html文檔,對(duì)其中的html元素進(jìn)行操作 (PHP5+以上版本) 下載地址: https://github.com/samacs/simple_html_dom 解 析器不僅僅只是幫助我們驗(yàn)證
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁(yè)面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對(duì)圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問(wèn)控制的和運(yùn)算符優(yōu)先級(jí)介紹
- 關(guān)于PHP語(yǔ)言構(gòu)造器介紹
- php/js獲取客戶(hù)端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國(guó)語(yǔ)言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
PHP教程Rss訂閱編程教程搜索
PHP教程推薦
- 關(guān)于 PHP 和 MySQL 時(shí)區(qū)的總結(jié)
- PHP實(shí)例 PHP實(shí)現(xiàn)定時(shí)生成HTML網(wǎng)站首頁(yè)
- PHP與Javascript的兩種交互方式
- 詳細(xì)講解PHP的Jmai組件及發(fā)送郵件實(shí)例
- PHP編程之PHP無(wú)限極分類(lèi)
- PHP教程之實(shí)現(xiàn)文本文件直接調(diào)用
- 《PHP設(shè)計(jì)模式介紹》第十章 規(guī)范模式
- 談PHP識(shí)別24位BMP的驗(yàn)證碼
- URL 長(zhǎng)度有限制嗎?
- 利用PHP的OOP特性實(shí)現(xiàn)數(shù)據(jù)保護(hù)
- 相關(guān)鏈接:
復(fù)制本頁(yè)鏈接| 搜索php 注冊(cè)時(shí)輸入信息驗(yàn)證器的實(shí)現(xiàn)詳解(2)
- 教程說(shuō)明:
PHP教程-php 注冊(cè)時(shí)輸入信息驗(yàn)證器的實(shí)現(xiàn)詳解(2)
。