PHP用户验证和标签推荐的简单使用
发布时间:2016-11-27 09:24:05 所属栏目:大数据 来源:站长网
导读:本文给大家讲解一些最简单的验证知识。大家可以先看下效果图,如果大家感觉还不错,请参考实现代码。 效果图 bookmark_fns.php lt;#63;phprequire_once('output_fns.php');require_once('db_fns.php');require_once('data_valid_fns.php');require_once('u
register_form.php lt;#63;php require_once('bookmark_fns.php'); do_html_header('User Registration'); display_registration_form(); do_html_footer(); #63;gt; register_new.php lt;#63;php require_once('bookmark_fns.php'); // vars $email = $_POST['email']; $username = $_POST['username']; $passwd = $_POST['passwd']; $passwd2 = $_POST['passwd2']; // start session session_start(); // valid data try { if (!filled_out($_POST)) { throw new Exception("You have not filled the form out correctly - please go back and try again.", 1); } if (!valid_email($email)) { throw new Exception("That is not a valid email address - please go back and try again.", 1); } if ($passwd != $passwd2) { throw new Exception("The passwords you entered do not match - please go back and try again.", 1); } if ((strlen($passwd) lt; 6) || (strlen($passwd) gt; 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 -gt; getMessage(); do_html_footer(); exit(); } #63;gt; forgot_form.php lt;#63;php require_once('bookmark_fns.php'); do_html_header('Reset password'); display_forgot_form(); do_html_footer(); #63;gt; forgot_passwd.php lt;#63;php require_once('bookmark_fns.php'); do_html_header('Resetting password'); $username = $_POST['username']; try { // get random password $password = reset_password($username); notify_password($username, $password); echo "Your new password has been emailed to you.lt;br /gt;"; }catch(Exception $e){ echo "Your password could not be reset - please try again later."; } do_html_url('login.php', 'Login'); do_html_footer(); #63;gt; change_passwd_form.php lt;#63;php require_once('bookmark_fns.php'); session_start(); do_html_header('Change password'); check_valid_user(); display_password_form(); display_user_menu(); do_html_footer(); #63;gt; change_passed.php lt;#63;php require_once('bookmark_fns.php'); session_start(); do_html_header('Changing password'); $old_passwd = $_POST['old_passwd']; $new_passwd = $_POST['new_passwd']; $new_passwd2 = $_POST['new_passwd2']; try { check_valid_user(); if (!filled_out($_POST)) { throw new Exception("You have not filled the form out correctly - please go back and try again.", 1); } if ($new_passwd != $new_passwd2) { throw new Exception("The passwords you entered do not match - please go back and try again.", 1); } if ((strlen($new_passwd) lt; 6) || (strlen($new_passwd) gt; 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 -gt; getMessage(); } display_user_menu(); do_html_footer(); #63;gt; add_bm_form.php lt;#63;php // include function files for this application require_once('bookmark_fns.php'); session_start(); // start output html do_html_header('Add Bookmarks'); check_valid_user(); display_add_bm_form(); display_user_menu(); do_html_footer(); #63;gt; add_bms.php lt;#63;php require_once('bookmark_fns.php'); session_start(); $new_url = $_POST['new_url']; do_html_header('Adding bookmarks'); try { check_valid_user(); if (!filled_out($_POST)) { throw new Exception('Form not completely filled out.'); } if (strstr($new_url, 'http://') === false) { $new_url = 'http://'.$new_url; } // check url is valid if (!@fopen($new_url, 'r')) { throw new Exception('Not a valid URL.'); } add_bm($new_url); echo "Bookmark added"; if ($mks = get_user_urls($_SESSION['valid_user'])) { display_user_urls($mks); } }catch(Exception $e) { echo $e -gt; getMessage(); } display_user_menu(); do_html_footer(); #63;gt; (编辑:宁德站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐