当前位置:Gxlcms > PHP教程 > PHP用户验证和标签推荐的简单使用

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

时间:2021-07-01 10:21:17 帮助过:23人阅读

这篇文章主要介绍了PHP用户验证和标签推荐的简单使用,本文给大家介绍的非常详细,具有参考借鉴价值,需要的朋友可以参考下

效果图

bookmark_fns.php

  1. <?php
  2. require_once('output_fns.php');
  3. require_once('db_fns.php');
  4. require_once('data_valid_fns.php');
  5. require_once('url_fns.php');
  6. require_once('user_auth_fns.php');
  7. ?>

data_valid_fns.php

  1. <?php
  2. // Test that each variable has a value
  3. function filled_out($form_vars) {
  4. foreach ($form_vars as $key => $value) {
  5. if ((!isset($key)) || ($value == '')) {
  6. return false;
  7. }
  8. }
  9. return true;
  10. }
  11. // Valid email
  12. function valid_email($address) {
  13. if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address)) {
  14. return true;
  15. }else {
  16. return false;
  17. }
  18. }
  19. ?>

db_fns.php

  1. <?php
  2. //Conncet to db
  3. function db_connect() {
  4. $db = new mysqli('127.0.0.1', 'bm_user', 'password', 'bookmarks');
  5. if (!$db) {
  6. throw new Exception("Could not connect to database server", 1);
  7. }else {
  8. return $db;
  9. }
  10. }
  11. ?>

user_auth_fns.php

  1. <?php
  2. require_once('db_fns.php');
  3. // register
  4. function register($username, $email, $password) {
  5. $conn = db_connect();
  6. $results = $conn -> query("select * from user where username = '".$username."'");
  7. if (!$results) {
  8. throw new Exception("Could not execute query", 1);
  9. }
  10. if ($results -> num_rows > 0) {
  11. throw new Exception("That username is taken - go back and choose another one.", 1);
  12. }
  13. $results = $conn -> query("insert into user values ('".$username."', sha1('".$email."'), '".$password."')");
  14. if (!$results) {
  15. throw new Exception('Could not register you in database - please try again later.');
  16. }
  17. return true;
  18. }
  19. // Log in
  20. function login($username, $password) {
  21. $conn = db_connect();
  22. $results = $conn -> query("select * from user where username = '".$username."' and passwd = sha1('".$password."')");
  23. if (!$results) {
  24. throw new Exception('Could not log you in.');
  25. }
  26. if ($results -> num_rows > 0) {
  27. return true;
  28. }else {
  29. throw new Exception('Could not log you in.');
  30. }
  31. }
  32. // Check valid user
  33. function check_valid_user() {
  34. if (isset($_SESSION['valid_user'])) {
  35. echo "Logged in as ".$_SESSION['valid_user'].".<br />";
  36. }else {
  37. do_html_header('Problem:');
  38. echo "You are not logged in.<br />";
  39. do_html_url('login.php', 'Login');
  40. do_html_foot();
  41. exit;
  42. }
  43. }
  44. // change password
  45. function change_password($username, $old_password, $new_password) {
  46. login($username, $old_password);
  47. $conn = db_connect();
  48. $result = $conn -> query("update user set passwd = sha1('".$new_password."') where username = '".$username."'");
  49. if (!$result) {
  50. throw new Exception('Password could not be changed.');
  51. } else {
  52. return true; // changed successfully
  53. }
  54. }
  55. function get_random_word($min_length, $max_length) {
  56. // grab a random word from dictionary between the two lengths
  57. // and return it
  58. // generate a random word
  59. $word = '';
  60. // remember to change this path to suit your system
  61. $dictionary = '/usr/dict/words'; // the ispell dictionary
  62. $fp = @fopen($dictionary, 'r');
  63. if(!$fp) {
  64. return false;
  65. }
  66. $size = filesize($dictionary);
  67. // go to a random location in dictionary
  68. $rand_location = rand(0, $size);
  69. fseek($fp, $rand_location);
  70. // get the next whole word of the right length in the file
  71. while ((strlen($word) < $min_length) || (strlen($word)>$max_length) || (strstr($word, "'"))) {
  72. if (feof($fp)) {
  73. fseek($fp, 0); // if at end, go to start
  74. }
  75. $word = fgets($fp, 80); // skip first word as it could be partial
  76. $word = fgets($fp, 80); // the potential password
  77. }
  78. $word = trim($word); // trim the trailing \n from fgets
  79. return $word;
  80. }
  81. function reset_password($username) {
  82. // set password for username to a random value
  83. // return the new password or false on failure
  84. // get a random dictionary word b/w 6 and 13 chars in length
  85. $new_password = get_random_word(6, 13);
  86. if($new_password == false) {
  87. throw new Exception('Could not generate new password.');
  88. }
  89. // add a number between 0 and 999 to it
  90. // to make it a slightly better password
  91. $rand_number = rand(0, 999);
  92. $new_password .= $rand_number;
  93. // set user's password to this in database or return false
  94. $conn = db_connect();
  95. $result = $conn->query("update user
  96. set passwd = sha1('".$new_password."')
  97. where username = '".$username."'");
  98. if (!$result) {
  99. throw new Exception('Could not change password.'); // not changed
  100. } else {
  101. return $new_password; // changed successfully
  102. }
  103. }
  104. function notify_password($username, $password) {
  105. // notify the user that their password has been changed
  106. $conn = db_connect();
  107. $result = $conn->query("select email from user
  108. where username='".$username."'");
  109. if (!$result) {
  110. throw new Exception('Could not find email address.');
  111. } else if ($result->num_rows == 0) {
  112. throw new Exception('Could not find email address.');
  113. // username not in db
  114. } else {
  115. $row = $result->fetch_object();
  116. $email = $row->email;
  117. $from = "From: support@phpbookmark \r\n";
  118. $mesg = "Your PHPBookmark password has been changed to ".$password."\r\n"
  119. ."Please change it next time you log in.\r\n";
  120. if (mail($email, 'PHPBookmark login information', $mesg, $from)) {
  121. return true;
  122. } else {
  123. throw new Exception('Could not send email.');
  124. }
  125. }
  126. }
  127. ?>

url_fns.php

  1. <?php
  2. require_once('db_fns.php');
  3. // Get user urls
  4. function get_user_urls($username) {
  5. $conn = db_connect();
  6. $results = $conn -> query("select bm_URL
  7. from bookmark
  8. where username = '" . $username . "'");
  9. if (!$results) {
  10. return false;
  11. }
  12. $url_array = array();
  13. for ($i = 1;$row = $results -> fetch_row();++$i) {
  14. $url_array[$i] = $row[0];
  15. }
  16. return $url_array;
  17. }
  18. // Add url to db
  19. function add_bm($new_url) {
  20. echo "Attempting to add ".htmlspecialchars($new_url)."<br />";
  21. $valid_user = $_SESSION['valid_user'];
  22. $conn = db_connect();
  23. $results = $conn -> query(" select * from bookmark
  24. where username = '".$valid_user."'
  25. and bm_URL = '".$new_url."'");
  26. if ($results && ($results -> num_rows > 0)) {
  27. throw new Exception("Bookmark already exists.", 1);
  28. }
  29. $insert_result = $conn -> query("insert into bookmark values ('".$valid_user."', '".addslashes($new_url)."')");
  30. if (!$insert_result) {
  31. throw new Exception("Bookmark could not be inserted.", 1);
  32. }
  33. return true;
  34. }
  35. // Delete url
  36. function delete_bm($user, $url) {
  37. $conn = db_connect();
  38. $results = $conn -> query(" delete from bookmark
  39. where username = '".$user."'
  40. and bm_URL = '".$url."'");
  41. if (!$results) {
  42. throw new Exception("Bookmark could not be deleted.", 1);
  43. }
  44. return true;
  45. }
  46. function recommend_urls($valid_user, $popularity = 1) {
  47. $conn = db_connect();
  48. // $query = "select bm_URL
  49. // from bookmark
  50. // where username in
  51. // (select distinct(b2.username)
  52. // from bookmark b1, bookmark b2
  53. // where b1.username='".$valid_user."'
  54. // and b1.username != b2.username
  55. // and b1.bm_URL = b2.bm_URL)
  56. // and bm_URL not in
  57. // (select bm_URL
  58. // from bookmark
  59. // where username='".$valid_user."')
  60. // group by bm_url
  61. // having count(bm_url)>".$popularity;
  62. $query = "select bm_URL
  63. from bookmark
  64. where username in
  65. (select distinct(b2.username)
  66. from bookmark b1, bookmark b2
  67. where b1.username='".$valid_user."'
  68. and b1.username != b2.username
  69. and b1.bm_URL = b2.bm_URL)
  70. and bm_URL not in
  71. (select bm_URL
  72. from bookmark
  73. where username='".$valid_user."')
  74. group by bm_url
  75. having count(bm_url)>".$popularity;
  76. if (!($result = $conn->query($query))) {
  77. throw new Exception('Could not find any bookmarks to recommend.');
  78. }
  79. if ($result->num_rows==0) {
  80. throw new Exception('Could not find any bookmarks to recommend.');
  81. }
  82. $urls = array();
  83. // build an array of the relevant urls
  84. for ($count=0; $row = $result->fetch_object(); $count++) {
  85. $urls[$count] = $row->bm_URL;
  86. }
  87. return $urls;
  88. }
  89. ?>

output_fns.php

  1. <?php
  2. function do_html_header($title) {
  3. // print an HTML header
  4. ?>
  5. <html>
  6. <head>
  7. <title><?php echo $title;?></title>
  8. <style>
  9. body { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
  10. li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
  11. hr { color: #3333cc; width=300; text-align=left}
  12. a { color: #000000 }
  13. </style>
  14. </head>
  15. <body>
  16. <img src="005.png" alt="PHPbookmark logo" border="0"
  17. align="left" valign="bottom" height="55" width="57" />
  18. <h1>PHPbookmark</h1>
  19. <hr />
  20. <?php
  21. if($title) {
  22. do_html_heading($title);
  23. }
  24. }
  25. function do_html_footer() {
  26. // print an HTML footer
  27. ?>
  28. </body>
  29. </html>
  30. <?php
  31. }
  32. function do_html_heading($heading) {
  33. // print heading
  34. ?>
  35. <h2><?php echo $heading;?></h2>
  36. <?php
  37. }
  38. function do_html_URL($url, $name) {
  39. // output URL as link and br
  40. ?>
  41. <br /><a href="<?php echo $url;?>"><?php echo $name;?></a><br />
  42. <?php
  43. }
  44. function display_site_info() {
  45. // display some marketing info
  46. ?>
  47. <ul>
  48. <li>Store your bookmarks online with us!</li>
  49. <li>See what other users use!</li>
  50. <li>Share your favorite links with others!</li>
  51. </ul>
  52. <?php
  53. }
  54. function display_login_form() {
  55. ?>
  56. <p><a href="register_form.php">Not a member?</a></p>
  57. <form method="post" action="member.php">
  58. <table bgcolor="#cccccc">
  59. <tr>
  60. <td colspan="2">Members log in here:</td>
  61. <tr>
  62. <td>Username:</td>
  63. <td><input type="text" name="username"/></td></tr>
  64. <tr>
  65. <td>Password:</td>
  66. <td><input type="password" name="passwd"/></td></tr>
  67. <tr>
  68. <td colspan="2" align="center">
  69. <input type="submit" value="Log in"/></td></tr>
  70. <tr>
  71. <td colspan="2"><a href="forgot_form.php">Forgot your password?</a></td>
  72. </tr>
  73. </table></form>
  74. <?php
  75. }
  76. function display_registration_form() {
  77. ?>
  78. <form method="post" action="register_new.php">
  79. <table bgcolor="#cccccc">
  80. <tr>
  81. <td>Email address:</td>
  82. <td><input type="text" name="email" size="30" maxlength="100"/></td></tr>
  83. <tr>
  84. <td>Preferred username <br />(max 16 chars):</td>
  85. <td valign="top"><input type="text" name="username"
  86. size="16" maxlength="16"/></td></tr>
  87. <tr>
  88. <td>Password <br />(between 6 and 16 chars):</td>
  89. <td valign="top"><input type="password" name="passwd"
  90. size="16" maxlength="16"/></td></tr>
  91. <tr>
  92. <td>Confirm password:</td>
  93. <td><input type="password" name="passwd2" size="16" maxlength="16"/></td></tr>
  94. <tr>
  95. <td colspan=2 align="center">
  96. <input type="submit" value="Register"></td></tr>
  97. </table></form>
  98. <?php
  99. }
  100. function display_user_urls($url_array) {
  101. // display the table of URLs
  102. // set global variable, so we can test later if this is on the page
  103. global $bm_table;
  104. $bm_table = true;
  105. ?>
  106. <br />
  107. <form name="bm_table" action="delete_bms.php" method="post">
  108. <table width="300" cellpadding="2" cellspacing="0">
  109. <?php
  110. $color = "#cccccc";
  111. echo "<tr bgcolor=\"".$color."\"><td><strong>Bookmark</strong></td>";
  112. echo "<td><strong>Delete?</strong></td></tr>";
  113. if ((is_array($url_array)) && (count($url_array) > 0)) {
  114. foreach ($url_array as $url) {
  115. if ($color == "#cccccc") {
  116. $color = "#ffffff";
  117. } else {
  118. $color = "#cccccc";
  119. }
  120. //remember to call htmlspecialchars() when we are displaying user data
  121. echo "<tr bgcolor=\"".$color."\"><td><a href=\"".$url."\">".htmlspecialchars($url)."</a></td>
  122. <td><input type=\"checkbox\" name=\"del_me[]\"
  123. value=\"".$url."\"/></td>
  124. </tr>";
  125. }
  126. } else {
  127. echo "<tr><td>No bookmarks on record</td></tr>";
  128. }
  129. ?>
  130. </table>
  131. </form>
  132. <?php
  133. }
  134. function display_user_menu() {
  135. // display the menu options on this page
  136. ?>
  137. <hr />
  138. <a href="member.php">Home</a> |
  139. <a href="add_bm_form.php">Add BM</a> |
  140. <?php
  141. // only offer the delete option if bookmark table is on this page
  142. global $bm_table;
  143. if ($bm_table == true) {
  144. echo "<a href=\"#\" onClick=\"bm_table.submit();\">Delete BM</a> | ";
  145. } else {
  146. echo "<span style=\"color: #cccccc\">Delete BM</span> | ";
  147. }
  148. ?>
  149. <a href="change_passwd_form.php">Change password</a>
  150. <br />
  151. <a href="recommend.php">Recommend URLs to me</a> |
  152. <a href="logout.php">Logout</a>
  153. <hr />
  154. <?php
  155. }
  156. function display_add_bm_form() {
  157. // display the form for people to ener a new bookmark in
  158. ?>
  159. <form name="bm_table" action="add_bms.php" method="post">
  160. <table width="250" cellpadding="2" cellspacing="0" bgcolor="#cccccc">
  161. <tr><td>New BM:</td>
  162. <td><input type="text" name="new_url" value="http://"
  163. size="30" maxlength="255"/></td></tr>
  164. <tr><td colspan="2" align="center">
  165. <input type="submit" value="Add bookmark"/></td></tr>
  166. </table>
  167. </form>
  168. <?php
  169. }
  170. function display_password_form() {
  171. // display html change password form
  172. ?>
  173. <br />
  174. <form action="change_passwd.php" method="post">
  175. <table width="250" cellpadding="2" cellspacing="0" bgcolor="#cccccc">
  176. <tr><td>Old password:</td>
  177. <td><input type="password" name="old_passwd"
  178. size="16" maxlength="16"/></td>
  179. </tr>
  180. <tr><td>New password:</td>
  181. <td><input type="password" name="new_passwd"
  182. size="16" maxlength="16"/></td>
  183. </tr>
  184. <tr><td>Repeat new password:</td>
  185. <td><input type="password" name="new_passwd2"
  186. size="16" maxlength="16"/></td>
  187. </tr>
  188. <tr><td colspan="2" align="center">
  189. <input type="submit" value="Change password"/>
  190. </td></tr>
  191. </table>
  192. <br />
  193. <?php
  194. }
  195. function display_forgot_form() {
  196. // display HTML form to reset and email password
  197. ?>
  198. <br />
  199. <form action="forgot_passwd.php" method="post">
  200. <table width="250" cellpadding="2" cellspacing="0" bgcolor="#cccccc">
  201. <tr><td>Enter your username</td>
  202. <td><input type="text" name="username" size="16" maxlength="16"/></td>
  203. </tr>
  204. <tr><td colspan=2 align="center">
  205. <input type="submit" value="Change password"/>
  206. </td></tr>
  207. </table>
  208. <br />
  209. <?php
  210. }
  211. function display_recommended_urls($url_array) {
  212. // similar output to display_user_urls
  213. // instead of displaying the users bookmarks, display recomendation
  214. ?>
  215. <br />
  216. <table width="300" cellpadding="2" cellspacing="0">
  217. <?php
  218. $color = "#cccccc";
  219. echo "<tr bgcolor=\"".$color."\">
  220. <td><strong>Recommendations</strong></td></tr>";
  221. if ((is_array($url_array)) && (count($url_array)>0)) {
  222. foreach ($url_array as $url) {
  223. if ($color == "#cccccc") {
  224. $color = "#ffffff";
  225. } else {
  226. $color = "#cccccc";
  227. }
  228. echo "<tr bgcolor=\"".$color."\">
  229. <td><a href=\"".$url."\">".htmlspecialchars($url)."</a></td></tr>";
  230. }
  231. } else {
  232. echo "<tr><td>No recommendations for you today.</td></tr>";
  233. }
  234. ?>
  235. </table>
  236. <?php
  237. }
  238. ?>
  239. login.php
  240. <?php
  241. require_once('bookmark_fns.php');
  242. do_html_header('');
  243. display_site_info();
  244. display_login_form();
  245. do_html_footer();
  246. ?>
  247. logout.php
  248. <?php

require_once('bookmark_fns.php');

  1. // start session
  2. session_start();
  3. $old_user = $_SESSION['valid_user'];
  4. unset($_SESSION['valid_user']);
  5. $result_dest = session_destroy();
  6. do_html_header('Logging out');
  7. if (!empty($old_user)) {
  8. if ($result_dest) {
  9. echo 'Logged out.<br />';
  10. do_html_url('login.php', 'Login');
  11. }else {
  12. echo 'Could not log you out.<br />';
  13. }
  14. }else {
  15. echo 'You are not logged in ,so have not been logged out.<br />';
  16. do_html_url('login.php', 'Login');
  17. }
  18. do_html_footer();
  19. ?>

register_form.php

  1. <?php
  2. require_once('bookmark_fns.php');
  3. do_html_header('User Registration');
  4. display_registration_form();
  5. do_html_footer();
  6. ?>
  7. register_new.php
  8. <?php
  9. require_once('bookmark_fns.php');
  10. // vars
  11. $email = $_POST['email'];
  12. $username = $_POST['username'];
  13. $passwd = $_POST['passwd'];
  14. $passwd2 = $_POST['passwd2'];
  15. // start session
  16. session_start();
  17. // valid data
  18. try {
  19. if (!filled_out($_POST)) {
  20. throw new Exception("You have not filled the form out correctly - please go back and try again.", 1);
  21. }
  22. if (!valid_email($email)) {
  23. throw new Exception("That is not a valid email address - please go back and try again.", 1);
  24. }
  25. if ($passwd != $passwd2) {
  26. throw new Exception("The passwords you entered do not match - please go back and try again.", 1);
  27. }
  28. if ((strlen($passwd) < 6) || (strlen($passwd) > 16)) {
  29. throw new Exception("Your password must be between 6 and 16 characters - please go back and try again.", 1);
  30. }
  31. register($username, $passwd, $email);
  32. $_SESSION['valid_user'] = $username;
  33. do_html_header('Rigistration successful');
  34. do_html_url('member.php', 'Go to members page');
  35. do_html_footer();
  36. } catch (Exception $e) {
  37. do_html_header('Problem: ');
  38. echo $e -> getMessage();
  39. do_html_footer();
  40. exit();
  41. }
  42. ?>

forgot_form.php

  1. <?php
  2. require_once('bookmark_fns.php');
  3. do_html_header('Reset password');
  4. display_forgot_form();
  5. do_html_footer();
  6. ?>
  7. forgot_passwd.php
  8. <?php
  9. require_once('bookmark_fns.php');
  10. do_html_header('Resetting password');
  11. $username = $_POST['username'];
  12. try {
  13. // get random password
  14. $password = reset_password($username);
  15. notify_password($username, $password);
  16. echo "Your new password has been emailed to you.<br />";
  17. }catch(Exception $e){
  18. echo "Your password could not be reset - please try again later.";
  19. }
  20. do_html_url('login.php', 'Login');
  21. do_html_footer();
  22. ?>
  23. change_passwd_form.php
  24. <?php
  25. require_once('bookmark_fns.php');
  26. session_start();
  27. do_html_header('Change password');
  28. check_valid_user();
  29. display_password_form();
  30. display_user_menu();
  31. do_html_footer();
  32. ?>
  33. change_passed.php
  34. <?php
  35. require_once('bookmark_fns.php');
  36. session_start();
  37. do_html_header('Changing password');
  38. $old_passwd = $_POST['old_passwd'];
  39. $new_passwd = $_POST['new_passwd'];
  40. $new_passwd2 = $_POST['new_passwd2'];
  41. try {
  42. check_valid_user();
  43. if (!filled_out($_POST)) {
  44. throw new Exception("You have not filled the form out correctly - please go back and try again.", 1);
  45. }
  46. if ($new_passwd != $new_passwd2) {
  47. throw new Exception("The passwords you entered do not match - please go back and try again.", 1);
  48. }
  49. if ((strlen($new_passwd) < 6) || (strlen($new_passwd) > 16)) {
  50. throw new Exception("Your password must be between 6 and 16 characters - please go back and try again.", 1);
  51. }
  52. change_password($_SESSION['valid_user'], $old_passwd, $new_passwd2);
  53. echo 'Password changed.';
  54. }catch(Exception $e) {
  55. echo $e -> getMessage();
  56. }
  57. display_user_menu();
  58. do_html_footer();
  59. ?>
  60. add_bm_form.php
  61. <?php
  62. // include function files for this application
  63. require_once('bookmark_fns.php');
  64. session_start();
  65. // start output html
  66. do_html_header('Add Bookmarks');
  67. check_valid_user();
  68. display_add_bm_form();
  69. display_user_menu();
  70. do_html_footer();
  71. ?>

add_bms.php

  1. <?php
  2. require_once('bookmark_fns.php');
  3. session_start();
  4. $new_url = $_POST['new_url'];
  5. do_html_header('Adding bookmarks');
  6. try {
  7. check_valid_user();
  8. if (!filled_out($_POST)) {
  9. throw new Exception('Form not completely filled out.');
  10. }
  11. if (strstr($new_url, 'http://') === false) {
  12. $new_url = 'http://'.$new_url;
  13. }
  14. // check url is valid
  15. if (!@fopen($new_url, 'r')) {
  16. throw new Exception('Not a valid URL.');
  17. }
  18. add_bm($new_url);
  19. echo "Bookmark added";
  20. if ($mks = get_user_urls($_SESSION['valid_user'])) {
  21. display_user_urls($mks);
  22. }
  23. }catch(Exception $e) {
  24. echo $e -> getMessage();
  25. }
  26. display_user_menu();
  27. do_html_footer();
  28. ?>

delete_bms.php

  1. <?php
  2. require_once('bookmark_fns.php');
  3. session_start();
  4. $del_me = $_POST['del_me'];
  5. $valid_user = $_SESSION['valid_user'];
  6. do_html_header('Deleting bookmarks');
  7. check_valid_user();
  8. if (!filled_out($_POST)) {
  9. echo "<p>You have not chosen any bookmarks to delete.<br />
  10. Please try again.</p>";
  11. display_user_menu();
  12. do_html_footer();
  13. exit;
  14. }else {
  15. if (count($del_me) > 0) {
  16. foreach ($del_me as $url) {
  17. if (delete_bm($valid_user, $url)) {
  18. echo "Deleted ".htmlspecialchars($url)."<br />";
  19. }else {
  20. echo "Could not deleted ".htmlspecialchars($url)."<br />";
  21. }
  22. }
  23. }else {
  24. echo "No bookmarks selected for deletion.";
  25. }
  26. }
  27. if ($mks = get_user_urls($_SESSION['valid_user'])) {
  28. display_user_urls($mks);
  29. }
  30. display_user_menu();
  31. do_html_footer();
  32. ?>

recommend.php

  1. <?php
  2. require_once('bookmark_fns.php');
  3. session_start();
  4. do_html_header('Recommending URLS');
  5. try {
  6. check_valid_user();
  7. $urls = recommend_urls($_SESSION['valid_user'], 1);
  8. display_recommended_urls($urls);
  9. }catch(Exception $e) {
  10. echo $e -> getMessage();
  11. }
  12. display_user_menu();
  13. do_html_footer();
  14. ?>

member.php

  1. <?php
  2. require_once('bookmark_fns.php');
  3. session_start();
  4. @$username = $_POST['username'];
  5. @$passwd = $_POST['passwd'];
  6. if ($username && $passwd) {
  7. try {
  8. // Log in
  9. login($username, $passwd);
  10. $_SESSION['valid_user'] = $username;
  11. }catch(Exception $e) {
  12. do_html_header('Problem: ');
  13. echo "You could not be logged in. You must be logged in to view this page.";
  14. do_html_url('login.php', 'Login');
  15. do_html_footer();
  16. exit;
  17. }
  18. }
  19. do_html_header('Home');
  20. check_valid_user();
  21. if ($url_array = get_user_urls($_SESSION['valid_user'])) {
  22. display_user_urls($url_array);
  23. }
  24. display_user_menu();
  25. do_html_footer();
  26. ?>

以上就是本文的全部内容,希望对大家的学习有所帮助。

相关推荐:

php替换文章图片路径到本地服务器步骤详解

PHP对源代码加密方法总结

php与js打开本地exe应用程序传递参数步骤详解


以上就是PHP用户验证和标签推荐的简单使用的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行