PHP在線書簽系統(tǒng)分享
本文為大家分享了PHP在線書簽系統(tǒng),感興趣的小伙伴們可以參考一下
1、需求分析
首先,需要識(shí)別每個(gè)用戶。應(yīng)該有驗(yàn)證機(jī)制。
其次,需要保存單個(gè)用戶的書簽。用戶應(yīng)該能夠添加和刪除書簽。
再次,需要根據(jù)對(duì)他們的了解,向用戶建議他們可能感興趣的站點(diǎn)。
2、解決方案
2.1 系統(tǒng)流程圖

2.2 PHPbookmark中的文件列表

3、實(shí)現(xiàn)數(shù)據(jù)庫
create database bookmarks; use bookmarks; create table user ( username varchar(16) primary key, passwd char(40) not null, email varchar(100) not null ); create table bookmark ( username varchar(16) not null, bm_URL varchar(255) not null, index (username), index (bm_URL) ); grant select, insert, update, delete on bookmarks.* to bm_user@localhost identified by 'password';
4、實(shí)現(xiàn)基本的網(wǎng)站
4.1 login.php
<?php
/**
* 包含系統(tǒng)登錄表單的頁面
*/
//require_once語句和require語句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過,如果是則不會(huì)再次包含。
require_once('bookmark_fns.php'); //應(yīng)用程序的包含文件集合
do_html_header(''); //HTML標(biāo)題
display_site_info();//HTML站點(diǎn)信息
display_login_form();//HTML登錄信息
do_html_footer(); //HTML頁腳
?>
4.2 bookmark_fns.php
<?php
/**
* 應(yīng)用程序的包含文件集合
*/
//require_once語句和require語句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過,如果是則不會(huì)再次包含。
require_once('data_valid_fns.php'); //確認(rèn)用戶輸入數(shù)據(jù)有效的函數(shù)
require_once('db_fns.php'); // 連接數(shù)據(jù)庫的函數(shù)
require_once('user_auth_fns.php'); //用戶身份驗(yàn)證的函數(shù)
require_once('output_fns.php'); //以HTML形式格式化輸出的函數(shù)
require_once('url_fns.php'); //增加和刪除書簽的函數(shù)
?>
5、實(shí)現(xiàn)用戶身份驗(yàn)證
5.1 register_form.php
<?php
/**
* 系統(tǒng)中用戶注冊表單
*/
//require_once語句和require語句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過,如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
do_html_header('User Registration'); //HTML標(biāo)題
display_registeration_form(); //輸出注冊表單
do_html_footer(); //HTML頁腳
?>
5.2 register_new.php
<?php
/**
* 處理新注冊信息的腳本
*/
//require_once語句和require語句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過,如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
//創(chuàng)建變量
$email = $_POST['email'];
$username = $_POST['username'];
$passwd = $_POST['passwd'];
$passwd2 = $_POST['passwd2'];
//開啟會(huì)話
session_start();
try
{
//檢查表單是否填寫滿
if(!filled_out($_POST))
{
throw new exception('You have not filled the form out correctly - please go back and try again.');
}
//檢查郵件地址是否有效
if(!valid_email($email))
{
throw new exception('That is not a vald email address. Please go back try again.');
}
//檢查兩次輸入密碼是否相同
if($passwd != $passwd2)
{
throw new exception('The passwords you entered do not match - please go back try again.');
}
//檢查密碼長度是否合格
if((strlen($passwd) < 6) || (strlen($passwd) > 16))
{
throw new exception('Your password must be between 6 and 16 characters Please go back and try again.');
}
//嘗試注冊
register($username,$email,$passwd);
//注冊會(huì)話變量
$_SESSION['valid_user'] = $username;
//提供成員頁面鏈接
do_html_header('Registration successful'); //HTML標(biāo)題
echo 'Your registration was successful.Go to the members page to start setting up your bookmarks!'; //輸出URL
do_html_URL('member.php','Go to members page'); //HTML頁腳
do_html_footer(); //HTML頁腳
}
catch(exception $e)
{
do_html_header('Problem:');
echo $e->getMessage();
do_html_footer();
exit;
}
?>
5.3 member.php
<?php
/**
* 用戶的主頁面,包含該用戶所有的當(dāng)前書簽
*/
//require_once語句和require語句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過,如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
session_start();
//創(chuàng)建變量
$username = @$_POST['username'];
$passwd = @$_POST['passwd'];
if($username && $passwd)
{
try
{
login($username,$passwd);
//如果該用戶在數(shù)據(jù)庫中,則注冊會(huì)話變量
$_SESSION['valid_user'] = $username;
}
catch(exception $e)
{
//登錄不成功
do_html_header('Problem:');
echo 'You could not be logged in. You must be logged in to view this page.';
do_html_URL('login.php','Login');
do_html_footer();
exit;
}
}
do_html_header('Home');
check_valid_user();
//獲取用戶的書簽
if($url_array = get_user_urls($_SESSION['valid_user']))
display_user_urls($url_array);
//獲取用戶菜單選項(xiàng)
display_user_menu();
do_html_footer();
?>
5.4 logout.php
<?php
/**
* 將用戶注銷的腳本
*/
//require_once語句和require語句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過,如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
session_start();
$old_user = $_SESSION['valid_user'];
//注銷會(huì)話變量
unset($_SESSION['valid_user']);
$result_dest = session_destroy();
do_html_header('Logging Out');
if(!empty($old_user))
{
if($result_dest) //登出成功
{
echo 'Logged out.<br />';
do_html_URL('login.php','Login');
}
else //不成功
{
echo 'Could not log you out.<br />';
}
}
else
{
echo 'You were not logged in, and so have not been logged ot.<br />';
do_html_URL('login.php','Login');
}
do_html_footer();
?>
5.5 change_passwd.php
<?php
/**
* 修改數(shù)據(jù)庫中用戶密碼的表單
*/
//require_once語句和require語句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過,如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
session_start();
do_html_header('Changing password');
//創(chuàng)建變量
$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 out the form completely.Please try again.');
if($new_passwd != $new_passwd2)
throw new exception('Passwords entered were not the same. Not changed.');
if((strlen($new_passwd) > 16) || (strlen($new_passwd) < 6))
{
throw new exception('New password must be between 6 and 16 characters. Try again.');
}
//嘗試修改
change_password($_SESSION['valid_user'],$old_passwd,$new_passwd);
echo 'Password changed.';
}
catch(exception $e)
{
echo $e ->getMessage();
}
display_user_menu();
do_html_footer();
?>
5.6 forgot_paswd.php
<?php
/**
* 重新設(shè)置遺忘密碼的腳本
*/
//require_once語句和require語句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過,如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
do_html_header("Resetting password");
//創(chuàng)建變量
$username = $_POST['username'];
try
{
$passwd = reset_password($username);
notify_password($username,$passwd);
echo 'Your new password has been emailed to you.<br />';
}
catch(exception $e)
{
echo 'Your password could not be reset - please try again later.';
}
do_html_URL('login.php','Login');
do_html_footer();
?>
6、實(shí)現(xiàn)書簽的存儲(chǔ)和檢索
6.1 add_bms.php
<?php
/**
* 添加書簽的表單
*/
//require_once語句和require語句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過,如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
session_start();
//創(chuàng)建變量
$new_url = $_POST['new_url'];
do_html_header('Adding bookmarks');
try
{
check_valid_user(); //檢查用戶有效性
if(!filled_out($new_url)) //檢查表單是否填寫
throw new exception('Form not completely filled out.');
if(strstr($new_url,'http://') === false)
$new_url = 'http://'. $new_url;
if(!(@fopen($new_url,'r'))) //可以調(diào)用fopen()函數(shù)打開URL,如果能打開這個(gè)文件,則假定URL是有效的
throw new exception('Not a valid URL.');
add_bm($new_url); //將URL添加到數(shù)據(jù)庫中
echo 'Bookmark added.';
if($url_array = get_user_urls($_SESSION['valid_user']))
display_user_urls($url_array);
}
catch(exception $e)
{
echo $e ->getMessage();
}
display_user_menu();
do_html_footer();
?>
6.2 delete_bms.php
<?php
/**
* 從用戶的書簽列表中刪除選定書簽的腳本呢
*/
//require_once語句和require語句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過,如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
session_start();
//創(chuàng)建變量
$del_me = @$_POST['del_me'];
$valid_user = $_SESSION['valid_user'];
do_html_header('Deleting bookmarks');
check_valid_user();
if(!filled_out($del_me)) //
{
echo '<p>You have not chosen any bookmarks to delete.<br />Please try again.</p>';
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) .'.<br />';
}
else
{
echo 'Could not delete '. htmlspecialchars($url) .'.<br />';
}
}
}
else
{
echo 'No bookmarks selected for deletion';
}
}
if($url_array = get_user_urls($valid_user))
{
display_user_urls($url_array);
}
display_user_menu();
do_html_footer();
?>
6.3 recommend.php
<?php
/**
* 基于用戶以前的操作,推薦用戶可能感興趣的書簽
*/
//require_once語句和require語句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過,如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
session_start();
do_html_header('Recommending URLs');
try
{
check_valid_user();
$urls = recommend_urls($_SESSION['valid_user']);
display_recommended_urls($urls);
}
catch(exception $e)
{
echo $e ->getMessage();
}
display_user_menu();
do_html_footer();
?>
以上就是PHP在線書簽系統(tǒng)的詳細(xì)代碼,希望對(duì)大家的學(xué)習(xí)有所幫助。
- 在線競拍系統(tǒng)的PHP實(shí)現(xiàn)框架(一)
- 在線競拍系統(tǒng)的PHP實(shí)現(xiàn)框架(二)
- PHP多用戶博客系統(tǒng)分析[想做多用戶博客的朋友,需要了解]
- php小型企業(yè)庫存管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)代碼
- PHP+MySQL投票系統(tǒng)的設(shè)計(jì)和實(shí)現(xiàn)分享
- 簡單的php新聞發(fā)布系統(tǒng)教程
- php實(shí)現(xiàn)模擬登陸方正教務(wù)系統(tǒng)抓取課表
- PHP實(shí)現(xiàn)簡單的新聞發(fā)布系統(tǒng)實(shí)例
相關(guān)文章
windows中為php安裝mongodb與memcache
這篇文章主要介紹了windows中為php安裝mongodb與memcache的方法,十分的詳盡,需要的朋友可以參考下2015-01-01
PHP簡單實(shí)現(xiàn)單點(diǎn)登錄功能示例
這篇文章主要介紹了PHP簡單實(shí)現(xiàn)單點(diǎn)登錄功能,結(jié)合實(shí)例形式分析了php基于session控制實(shí)現(xiàn)單點(diǎn)登錄的相關(guān)操作技巧,需要的朋友可以參考下2018-03-03
thinkPHP5框架自定義驗(yàn)證器實(shí)現(xiàn)方法分析
這篇文章主要介紹了thinkPHP5框架自定義驗(yàn)證器實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了thinkPHP自定義驗(yàn)證器的具體定義與使用方法,需要的朋友可以參考下2018-06-06

