侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

PHP用户验证和标签推荐的简单使用

php  /  管理员 发布于 7年前   142

本文给大家讲解一些最简单的验证知识。大家可以先看下效果图,如果大家感觉还不错,请参考实现代码。

效果图

bookmark_fns.php

data_valid_fns.php

 $value) {if ((!isset($key)) || ($value == '')) {return false;} } return true;}// Valid emailfunction valid_email($address) {if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address)) {return true;}else {return false;}}?>

db_fns.php

user_auth_fns.php

 query("select * from user where username = '".$username."'");if (!$results) {throw new Exception("Could not execute query", 1);}if ($results -> num_rows > 0) {throw new Exception("That username is taken - go back and choose another one.", 1);} $results = $conn -> query("insert into user values ('".$username."', sha1('".$email."'), '".$password."')");if (!$results) {throw new Exception('Could not register you in database - please try again later.');}return true;}// Log in function login($username, $password) {$conn = db_connect();$results = $conn -> query("select * from user where username = '".$username."' and passwd = sha1('".$password."')");if (!$results) {throw new Exception('Could not log you in.');}if ($results -> num_rows > 0) {return true;}else {throw new Exception('Could not log you in.');}}// Check valid user function check_valid_user() {if (isset($_SESSION['valid_user'])) {echo "Logged in as ".$_SESSION['valid_user'].".
";}else {do_html_header('Problem:');echo "You are not logged in.
";do_html_url('login.php', 'Login');do_html_foot();exit;}}// change password function change_password($username, $old_password, $new_password) {login($username, $old_password);$conn = db_connect();$result = $conn -> query("update user set passwd = sha1('".$new_password."') where username = '".$username."'");if (!$result) {throw new Exception('Password could not be changed.');} else {return true; // changed successfully}}function get_random_word($min_length, $max_length) {// grab a random word from dictionary between the two lengths// and return it// generate a random word$word = '';// remember to change this path to suit your system$dictionary = '/usr/dict/words'; // the ispell dictionary$fp = @fopen($dictionary, 'r');if(!$fp) {return false;}$size = filesize($dictionary);// go to a random location in dictionary$rand_location = rand(0, $size);fseek($fp, $rand_location);// get the next whole word of the right length in the filewhile ((strlen($word) < $min_length) || (strlen($word)>$max_length) || (strstr($word, "'"))) {if (feof($fp)) {fseek($fp, 0); // if at end, go to start}$word = fgets($fp, 80); // skip first word as it could be partial$word = fgets($fp, 80); // the potential password}$word = trim($word); // trim the trailing \n from fgetsreturn $word;}function reset_password($username) {// set password for username to a random value// return the new password or false on failure// get a random dictionary word b/w 6 and 13 chars in length$new_password = get_random_word(6, 13);if($new_password == false) {throw new Exception('Could not generate new password.');}// add a number between 0 and 999 to it// to make it a slightly better password$rand_number = rand(0, 999);$new_password .= $rand_number;// set user's password to this in database or return false$conn = db_connect();$result = $conn->query("update userset passwd = sha1('".$new_password."')where username = '".$username."'");if (!$result) {throw new Exception('Could not change password.'); // not changed} else {return $new_password; // changed successfully}}function notify_password($username, $password) {// notify the user that their password has been changed$conn = db_connect();$result = $conn->query("select email from userwhere username='".$username."'");if (!$result) {throw new Exception('Could not find email address.');} else if ($result->num_rows == 0) {throw new Exception('Could not find email address.');// username not in db} else {$row = $result->fetch_object();$email = $row->email;$from = "From: support@phpbookmark \r\n";$mesg = "Your PHPBookmark password has been changed to ".$password."\r\n"."Please change it next time you log in.\r\n";if (mail($email, 'PHPBookmark login information', $mesg, $from)) {return true;} else {throw new Exception('Could not send email.');}}}?>

url_fns.php

 query("select bm_URL from bookmark where username = '" . $username . "'");if (!$results) {return false;}$url_array = array();for ($i = 1;$row = $results -> fetch_row();++$i) {$url_array[$i] = $row[0];}return $url_array;}// Add url to dbfunction add_bm($new_url) {echo "Attempting to add ".htmlspecialchars($new_url)."
";$valid_user = $_SESSION['valid_user'];$conn = db_connect();$results = $conn -> query(" select * from bookmark where username = '".$valid_user."' and bm_URL = '".$new_url."'");if ($results && ($results -> num_rows > 0)) {throw new Exception("Bookmark already exists.", 1); }$insert_result = $conn -> query("insert into bookmark values ('".$valid_user."', '".addslashes($new_url)."')");if (!$insert_result) {throw new Exception("Bookmark could not be inserted.", 1); }return true;}// Delete url function delete_bm($user, $url) {$conn = db_connect();$results = $conn -> query(" delete from bookmark where username = '".$user."' and bm_URL = '".$url."'");if (!$results) {throw new Exception("Bookmark could not be deleted.", 1); }return true; }function recommend_urls($valid_user, $popularity = 1) {$conn = db_connect();// $query = "select bm_URL// from bookmark// where username in// (select distinct(b2.username)// from bookmark b1, bookmark b2// where b1.username='".$valid_user."'// and b1.username != b2.username// and b1.bm_URL = b2.bm_URL)// and bm_URL not in// (select bm_URL// from bookmark// where username='".$valid_user."')// group by bm_url// having count(bm_url)>".$popularity;$query = "select bm_URLfrom bookmarkwhere username in(select distinct(b2.username)from bookmark b1, bookmark b2where b1.username='".$valid_user."'and b1.username != b2.usernameand b1.bm_URL = b2.bm_URL)and bm_URL not in(select bm_URLfrom bookmarkwhere username='".$valid_user."')group by bm_urlhaving count(bm_url)>".$popularity;if (!($result = $conn->query($query))) {throw new Exception('Could not find any bookmarks to recommend.');}if ($result->num_rows==0) {throw new Exception('Could not find any bookmarks to recommend.');}$urls = array();// build an array of the relevant urlsfor ($count=0; $row = $result->fetch_object(); $count++) {$urls[$count] = $row->bm_URL;}return $urls;}?>

output_fns.php

<?php echo $title;?>

PHPbookmark




  • Store your bookmarks online with us!
  • See what other users use!
  • Share your favorite links with others!

Not a member?

Members log in here:
Username:
Password:
Forgot your password?
Email address:
Preferred username
(max 16 chars):
Password
(between 6 and 16 chars):
Confirm password:

";echo "";if ((is_array($url_array)) && (count($url_array) > 0)) {foreach ($url_array as $url) {if ($color == "#cccccc") {$color = "#ffffff";} else {$color = "#cccccc";}//remember to call htmlspecialchars() when we are displaying user dataecho "";}} else {echo "";}?>
BookmarkDelete?
".htmlspecialchars($url)."
No bookmarks on record

Home  | Add BM  | Delete BM  | ";}?>Change password
Recommend URLs to me  | Logout
New BM:

Old password:
New password:
Repeat new password:


Enter your username


";if ((is_array($url_array)) && (count($url_array)>0)) {foreach ($url_array as $url) {if ($color == "#cccccc") {$color = "#ffffff";} else {$color = "#cccccc";}echo "";}} else {echo "";}?>
Recommendations
".htmlspecialchars($url)."
No recommendations for you today.
login.phplogout.php

require_once('bookmark_fns.php');

// start sessionsession_start();$old_user = $_SESSION['valid_user'];unset($_SESSION['valid_user']);$result_dest = session_destroy();do_html_header('Logging out');if (!empty($old_user)) {if ($result_dest) {echo 'Logged out.
';do_html_url('login.php', 'Login');}else {echo 'Could not log you out.
';}}else {echo 'You are not logged in ,so have not been logged out.
';do_html_url('login.php', 'Login');}do_html_footer();?>

register_form.php

register_new.php 16)) { throw new Exception("Your password must be between 6 and 16 characters - please go back and try again.", 1);}register($username, $passwd, $email);$_SESSION['valid_user'] = $username;do_html_header('Rigistration successful');do_html_url('member.php', 'Go to members page');do_html_footer();} catch (Exception $e) {do_html_header('Problem: ');echo $e -> getMessage();do_html_footer();exit();}?>

forgot_form.php

forgot_passwd.php";}catch(Exception $e){echo "Your password could not be reset - please try again later.";}do_html_url('login.php', 'Login');do_html_footer();?>change_passwd_form.phpchange_passed.php 16)) { throw new Exception("Your password must be between 6 and 16 characters - please go back and try again.", 1);}change_password($_SESSION['valid_user'], $old_passwd, $new_passwd2);echo 'Password changed.';}catch(Exception $e) {echo $e -> getMessage();}display_user_menu(); do_html_footer();?>add_bm_form.php

add_bms.php

 getMessage();}display_user_menu();do_html_footer();?>

delete_bms.php

You have not chosen any bookmarks to delete.
Please try again.

";display_user_menu();do_html_footer();exit;}else {if (count($del_me) > 0) {foreach ($del_me as $url) {if (delete_bm($valid_user, $url)) {echo "Deleted ".htmlspecialchars($url)."
";}else {echo "Could not deleted ".htmlspecialchars($url)."
";}}}else {echo "No bookmarks selected for deletion.";}}if ($mks = get_user_urls($_SESSION['valid_user'])) {display_user_urls($mks);}display_user_menu();do_html_footer();?>

recommend.php

 getMessage();}display_user_menu();do_html_footer();?>

member.php

以上所述是小编给大家介绍的PHP用户验证和标签推荐的简单使用,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对站的支持!

您可能感兴趣的文章:

  • PHP登录验证功能示例【用户名、密码、验证码、数据库、已登陆验证、自动登录和注销登录等】
  • ubutu 16.04环境下,PHP与mysql数据库,网页登录验证实例讲解
  • php使用sql server验证连接数据库的方法
  • php验证用户名是否以字母开头与验证密码实例
  • php用户注册页面利用js进行表单验证具体实例
  • PHP+Ajax验证码验证用户登录
  • php面向对象的用户登录身份验证
  • PHP实现的用户注册表单验证功能简单示例
  • 通过缓存数据库结果提高PHP性能的原理介绍
  • PHP利用缓存处理用户注册时的邮箱验证,成功后用户数据存入数据库操作示例


  • 上一条:
    php 判断字符串编码是utf-8 或gb2312实例
    下一条:
    PHP实现小偷程序实例
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 用Time Warden监控PHP中的代码处理时间(0个评论)
    • 在PHP中使用array_pop + yield实现读取超大型目录功能示例(0个评论)
    • Property Hooks RFC在PHP 8.4中越来越接近现实(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-11
    • 2017-12
    • 2018-01
    • 2018-02
    • 2018-03
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-09
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    • 2024-05
    • 2024-06
    • 2024-07
    • 2024-09
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客