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

2.2 PHPbookmark中的文件列表

3、實(shí)現(xiàn)數(shù)據(jù)庫(kù)
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)登錄表單的頁(yè)面
*/
//require_once語(yǔ)句和require語(yǔ)句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過(guò),如果是則不會(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頁(yè)腳
?>
4.2 bookmark_fns.php
<?php
/**
* 應(yīng)用程序的包含文件集合
*/
//require_once語(yǔ)句和require語(yǔ)句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過(guò),如果是則不會(huì)再次包含。
require_once('data_valid_fns.php'); //確認(rèn)用戶(hù)輸入數(shù)據(jù)有效的函數(shù)
require_once('db_fns.php'); // 連接數(shù)據(jù)庫(kù)的函數(shù)
require_once('user_auth_fns.php'); //用戶(hù)身份驗(yàn)證的函數(shù)
require_once('output_fns.php'); //以HTML形式格式化輸出的函數(shù)
require_once('url_fns.php'); //增加和刪除書(shū)簽的函數(shù)
?>
5、實(shí)現(xiàn)用戶(hù)身份驗(yàn)證
5.1 register_form.php
<?php
/**
* 系統(tǒng)中用戶(hù)注冊(cè)表單
*/
//require_once語(yǔ)句和require語(yǔ)句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過(guò),如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
do_html_header('User Registration'); //HTML標(biāo)題
display_registeration_form(); //輸出注冊(cè)表單
do_html_footer(); //HTML頁(yè)腳
?>
5.2 register_new.php
<?php
/**
* 處理新注冊(cè)信息的腳本
*/
//require_once語(yǔ)句和require語(yǔ)句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過(guò),如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
//創(chuàng)建變量
$email = $_POST['email'];
$username = $_POST['username'];
$passwd = $_POST['passwd'];
$passwd2 = $_POST['passwd2'];
//開(kāi)啟會(huì)話(huà)
session_start();
try
{
//檢查表單是否填寫(xiě)滿(mǎn)
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.');
}
//檢查密碼長(zhǎng)度是否合格
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.');
}
//嘗試注冊(cè)
register($username,$email,$passwd);
//注冊(cè)會(huì)話(huà)變量
$_SESSION['valid_user'] = $username;
//提供成員頁(yè)面鏈接
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頁(yè)腳
do_html_footer(); //HTML頁(yè)腳
}
catch(exception $e)
{
do_html_header('Problem:');
echo $e->getMessage();
do_html_footer();
exit;
}
?>
5.3 member.php
<?php
/**
* 用戶(hù)的主頁(yè)面,包含該用戶(hù)所有的當(dāng)前書(shū)簽
*/
//require_once語(yǔ)句和require語(yǔ)句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過(guò),如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
session_start();
//創(chuàng)建變量
$username = @$_POST['username'];
$passwd = @$_POST['passwd'];
if($username && $passwd)
{
try
{
login($username,$passwd);
//如果該用戶(hù)在數(shù)據(jù)庫(kù)中,則注冊(cè)會(huì)話(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();
//獲取用戶(hù)的書(shū)簽
if($url_array = get_user_urls($_SESSION['valid_user']))
display_user_urls($url_array);
//獲取用戶(hù)菜單選項(xiàng)
display_user_menu();
do_html_footer();
?>
5.4 logout.php
<?php
/**
* 將用戶(hù)注銷(xiāo)的腳本
*/
//require_once語(yǔ)句和require語(yǔ)句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過(guò),如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
session_start();
$old_user = $_SESSION['valid_user'];
//注銷(xiāo)會(huì)話(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ù)庫(kù)中用戶(hù)密碼的表單
*/
//require_once語(yǔ)句和require語(yǔ)句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過(guò),如果是則不會(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語(yǔ)句和require語(yǔ)句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過(guò),如果是則不會(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)書(shū)簽的存儲(chǔ)和檢索
6.1 add_bms.php
<?php
/**
* 添加書(shū)簽的表單
*/
//require_once語(yǔ)句和require語(yǔ)句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過(guò),如果是則不會(huì)再次包含。
require_once('bookmark_fns.php');
session_start();
//創(chuàng)建變量
$new_url = $_POST['new_url'];
do_html_header('Adding bookmarks');
try
{
check_valid_user(); //檢查用戶(hù)有效性
if(!filled_out($new_url)) //檢查表單是否填寫(xiě)
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ù)打開(kāi)URL,如果能打開(kāi)這個(gè)文件,則假定URL是有效的
throw new exception('Not a valid URL.');
add_bm($new_url); //將URL添加到數(shù)據(jù)庫(kù)中
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
/**
* 從用戶(hù)的書(shū)簽列表中刪除選定書(shū)簽的腳本呢
*/
//require_once語(yǔ)句和require語(yǔ)句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過(guò),如果是則不會(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
/**
* 基于用戶(hù)以前的操作,推薦用戶(hù)可能感興趣的書(shū)簽
*/
//require_once語(yǔ)句和require語(yǔ)句完全相同,唯一區(qū)別是PHP會(huì)檢查該文件是否已經(jīng)被包含過(guò),如果是則不會(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在線書(shū)簽系統(tǒng)的詳細(xì)代碼,希望對(duì)大家的學(xué)習(xí)有所幫助。
- 在線競(jìng)拍系統(tǒng)的PHP實(shí)現(xiàn)框架(一)
- 在線競(jìng)拍系統(tǒng)的PHP實(shí)現(xiàn)框架(二)
- PHP多用戶(hù)博客系統(tǒng)分析[想做多用戶(hù)博客的朋友,需要了解]
- php小型企業(yè)庫(kù)存管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)代碼
- PHP+MySQL投票系統(tǒng)的設(shè)計(jì)和實(shí)現(xiàn)分享
- 簡(jiǎn)單的php新聞發(fā)布系統(tǒng)教程
- php實(shí)現(xiàn)模擬登陸方正教務(wù)系統(tǒng)抓取課表
- PHP實(shí)現(xiàn)簡(jiǎn)單的新聞發(fā)布系統(tǒng)實(shí)例
相關(guān)文章
如何用PHP來(lái)實(shí)現(xiàn)一個(gè)動(dòng)態(tài)Web服務(wù)器
這篇文章介紹了如何用PHP來(lái)實(shí)現(xiàn)一個(gè)動(dòng)態(tài)Web服務(wù)器,文章思路清晰,并附有演示代碼地址,需要的朋友可以參考下2015-07-07
ThinkPHP實(shí)現(xiàn)轉(zhuǎn)換數(shù)據(jù)庫(kù)查詢(xún)結(jié)果數(shù)據(jù)到對(duì)應(yīng)類(lèi)型的方法
這篇文章主要介紹了ThinkPHP實(shí)現(xiàn)轉(zhuǎn)換數(shù)據(jù)庫(kù)查詢(xún)結(jié)果數(shù)據(jù)到對(duì)應(yīng)類(lèi)型的方法,涉及thinkPHP模型類(lèi)操作及針對(duì)源碼文件的相關(guān)修改方法,需要的朋友可以參考下2017-11-11
php中simplexml_load_string使用實(shí)例分享
這篇文章主要介紹了php中simplexml_load_string使用實(shí)例,需要的朋友可以參考下2014-02-02
實(shí)用的簡(jiǎn)單PHP分頁(yè)集合包括使用方法
收集了三個(gè)PHP分頁(yè)方法,總會(huì)有一個(gè)適合你用的。2013-10-10
用Php編寫(xiě)注冊(cè)后Email激活驗(yàn)證的實(shí)例代碼
通過(guò)使用Email驗(yàn)證激活的方法,可以有效的幫你阻止惡意的Spam和注冊(cè)機(jī)器人的訪問(wèn)。 用php編寫(xiě)注冊(cè)后Email驗(yàn)證激活的步驟非常簡(jiǎn)單,相信幾分鐘之內(nèi)你就能學(xué)會(huì)。2013-03-03
PHP+Mysql無(wú)刷新問(wèn)答評(píng)論系統(tǒng)(源碼)
自己寫(xiě)的一個(gè)評(píng)論系統(tǒng)源碼分享給大家,包括有表情,還有評(píng)論機(jī)制,代碼簡(jiǎn)單易懂,需要的朋友參考下2016-12-12
Yii中實(shí)現(xiàn)處理前后臺(tái)登錄的新方法
這篇文章主要介紹了Yii中實(shí)現(xiàn)處理前后臺(tái)登錄的新方法,具體分析了Yii中前后臺(tái)登錄的新思路與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2015-12-12

