目录
Users you're following
Sorry, could not connect to database.
List of Users
首页 后端开发 php教程 小型 Twitter 的系统 流碼+註釋,PHP

小型 Twitter 的系统 流碼+註釋,PHP

Jun 13, 2016 am 10:58 AM
gt lt user users

小型 Twitter 的系统 源碼+註釋,PHP

?

今天重新吧 小型twitter系統的源碼 認真研究了一邊 算是熟悉php把?

爲今後一個月的畢業設計做打算

?

下載

http://dl.vmall.com/c0nkwafdqz

?

index

?

<?phpsession_start ();include_once ('header.php');include_once ('functions.php');$_SESSION ['userid'] = 1;//设置session真正情况是在登录的时候设置?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Microblogging Application</title></head><p>	<a href='users.php'>see list of users</a></p><?phpif (isset ( $_SESSION ['message'] )) {//如果session中设置了message就显示出来.然后释放	echo "<b>" . $_SESSION ['message'] . "</b>";	unset ( $_SESSION ['message'] );}?><form method='post' action='add.php'>	<p>Your status:</p>	<textarea name='body' rows='5' cols='40' wrap=VIRTUAL></textarea>	<p>		<input type='submit' value='submit' />	</p><?php$users = show_users($_SESSION['userid']);//显示用户follow的用戶if (count($users)){	$myusers = array_keys($users);//返回數組中所有的key}else{	$myusers = array();}$myusers[] = $_SESSION['userid'];//應該在myusers數據末尾添加用戶自己$posts = show_posts($myusers,5);//顯示用戶follow用戶的五條postif (count ( $posts )) {	?><table border='1' cellspacing='0' cellpadding='5' width='500'><?php	foreach ( $posts as $key => $list ) {		echo "<tr valign='top'>\n";		echo "<td>" . $list ['userid'] . "</td>\n";		echo "<td>" . $list ['body'] . "<br/>\n";		echo "<small>" . $list ['stamp'] . "</small></td>\n";		echo "</tr>\n";	}	?></table><?php} else {	?><p>		<b>You haven't posted anything yet!</b>	</p><?php}?><h2 id="Users-you-re-following">Users you're following</h2><?php$users = show_users ( $_SESSION ['userid'] );if (count ( $users )) {	?><ul><?php	foreach ( $users as $key => $value ) {		echo "<li>" . $value . "</li>\n";	}	?></ul><?php} else {	?><p>		<b>You're not following anyone yet!</b>	</p><?php}?></form></body></html>
登录后复制


headers

?

?

<?php$SERVER = 'localhost:3306';$USER = 'root';$PASS = 'root';$DATABASE = 'tweet';if (! ($mylink = mysql_connect ( $SERVER, $USER, $PASS ))) {	echo "<h3 id="Sorry-could-not-connect-to-database">Sorry, could not connect to database.</h3><br/>	Please contact your system's admin for more help\n";	exit ();}mysql_select_db ( $DATABASE );?>
登录后复制

users

<?phpsession_start ();include_once ("header.php");include_once ("functions.php");?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Microblogging Application - Users</title></head><body>	<h1 id="List-of-Users">List of Users</h1><?php$users = show_users ();$following = following(1);if (count ( $users )) {	?><table border='1' cellspacing='0' cellpadding='5' width='500'><?php	foreach ( $users as $key => $value ) {//=>指的是获取数组内某一个单元内的元素的内容,		echo "<tr valign='top'>\n";		echo "<td>" . $key . "</td>\n";//顯示id		echo "<td>" . $value;//顯示id對應的值也就是value					if (in_array ( $key, $following )) {//檢查key是否在following中 然后根据状态显示不同的值显示不同的信息 生成不同的指向action的链接			echo " <small>		<a href='action.php?id=$key&do=unfollow'>unfollow</a>		</small>";		} else {			echo " <small>		<a href='action.php?id=$key&do=follow'>follow</a>		</small>";		}		echo "</td>\n";		echo "</tr>\n";	}	?></table><?php} else {	?><p>		<b>There are no users in the system!</b>	</p><?php}?></body></html>
登录后复制



?

?

<?phpfunction add_post($userid, $body) {	$sql = "insert into posts (user_id, body, stamp) 			values ($userid, '" . mysql_real_escape_string ( $body ) . "',now())";		$result = mysql_query ( $sql );}function show_posts($userid, $limit = 0) {	$posts = array ();		$user_string = implode ( ',', $userid );	$extra = " and id in ($user_string)";		if ($limit > 0) {		$extra = "limit $limit";	} else {		$extra = '';	}		$sql = "select user_id,body, stamp from posts 		where user_id in ($user_string) 		order by stamp desc $extra";	echo $sql;	$result = mysql_query ( $sql );		while ( $data = mysql_fetch_object ( $result ) ) {		$posts [] = array (				'stamp' => $data->stamp,				'userid' => $data->user_id,				'body' => $data->body 		);	}	return $posts;}/** * 显示用户 * 如果user_id =0,直接显示所有用户 * 如果user id >0,显示改用户follow的用户id * @param unknown_type $user_id * @return multitype:|multitype:NULL */function show_users($user_id = 0) {	if ($user_id > 0) {		$follow = array ();		$fsql = "select user_id from following				where follower_id='$user_id'";//從follow中選出該id的follower		$fresult = mysql_query ( $fsql );						while ( $f = mysql_fetch_object ( $fresult ) ) {//把結果作爲一個對象傳入					array_push ( $follow, $f->user_id );//把f中的user_id字段放到follow中		}					if (count ( $follow )) {			$id_string = implode ( ',', $follow );//以","作爲分割符來加工這個字符串,爲了拼接後面的sql			$extra = " and id in ($id_string)";					} else {			return array ();		}	}		$users = array ();	$sql = "select id, username from users 		where status='active' 		$extra order by username";//從user表中選出follower的 id 和 name		$result = mysql_query ( $sql );		while ( $data = mysql_fetch_object ( $result ) ) {		$users [$data->id] = $data->username;//想user中填入用戶名	}	return $users;}/** * 搜索出用户follow的用户的id * @param unknown_type $userid * @return multitype: */function following($userid) {	$users = array ();		$sql = "select distinct user_id from following	where follower_id = '$userid'";	$result = mysql_query ( $sql );		while ( $data = mysql_fetch_object ( $result ) ) {		array_push ( $users, $data->user_id );	}		return $users;}function check_count($first, $second) {	$sql = "select count(*) from following	where user_id='$second' and follower_id='$first'";	$result = mysql_query ( $sql );		$row = mysql_fetch_row ( $result );	return $row [0];}function follow_user($me, $them) {	$count = check_count ( $me, $them );		if ($count == 0) {		$sql = "insert into following (user_id, follower_id)		values ($them,$me)";				$result = mysql_query ( $sql );	}}function unfollow_user($me, $them) {	$count = check_count ( $me, $them );		if ($count != 0) {		$sql = "delete from following		where user_id='$them' and follower_id='$me'		limit 1";				$result = mysql_query ( $sql );	}}?>
登录后复制


add

?

?

<?phpsession_start ();include_once ("header.php");include_once ("functions.php");$userid = $_SESSION ['userid'];$body = substr ( $_POST ['body'], 0, 140 );add_post ( $userid, $body );$_SESSION ['message'] = "Your post has been added!";header ( "Location:index.php" );?>
登录后复制


<?phpsession_start ();include_once ("header.php");include_once ("functions.php");/**  处理follow动作 */$id = $_GET ['id'];//获取get 方法传来的值 $_POST是post$do = $_GET ['do'];switch ($do) {	case "follow" :		follow_user ( $_SESSION ['userid'], $id );		$msg = "You have followed a user!";//设置信息		break;		case "unfollow" :		unfollow_user ( $_SESSION ['userid'], $id );		$msg = "You have unfollowed a user!";		break;}$_SESSION ['message'] = $msg;//在session中发送信息header ( "Location:index.php" );?>
登录后复制



本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
4 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

华为GT3 Pro和GT4的差异是什么? 华为GT3 Pro和GT4的差异是什么? Dec 29, 2023 pm 02:27 PM

许多用户在选择智能手表的时候都会选择的华为的品牌,其中华为GT3pro和GT4都是非常热门的选择,不少用户都很好奇华为GT3pro和GT4有什么区别,下面就就给大家介绍一下二者。华为GT3pro和GT4有什么区别一、外观GT4:46mm和41mm,材质是玻璃表镜+不锈钢机身+高分纤维后壳。GT3pro:46.6mm和42.9mm,材质是蓝宝石玻璃表镜+钛金属机身/陶瓷机身+陶瓷后壳二、健康GT4:采用最新的华为Truseen5.5+算法,结果会更加的精准。GT3pro:多了ECG心电图和血管及安

修复:截图工具在 Windows 11 中不起作用 修复:截图工具在 Windows 11 中不起作用 Aug 24, 2023 am 09:48 AM

为什么截图工具在Windows11上不起作用了解问题的根本原因有助于找到正确的解决方案。以下是截图工具可能无法正常工作的主要原因:对焦助手已打开:这可以防止截图工具打开。应用程序损坏:如果截图工具在启动时崩溃,则可能已损坏。过时的图形驱动程序:不兼容的驱动程序可能会干扰截图工具。来自其他应用程序的干扰:其他正在运行的应用程序可能与截图工具冲突。证书已过期:升级过程中的错误可能会导致此issu简单的解决方案这些适合大多数用户,不需要任何特殊的技术知识。1.更新窗口和Microsoft应用商店应用程

如何修复无法连接到iPhone上的App Store错误 如何修复无法连接到iPhone上的App Store错误 Jul 29, 2023 am 08:22 AM

第1部分:初始故障排除步骤检查苹果的系统状态:在深入研究复杂的解决方案之前,让我们从基础知识开始。问题可能不在于您的设备;苹果的服务器可能会关闭。访问Apple的系统状态页面,查看AppStore是否正常工作。如果有问题,您所能做的就是等待Apple修复它。检查您的互联网连接:确保您拥有稳定的互联网连接,因为“无法连接到AppStore”问题有时可归因于连接不良。尝试在Wi-Fi和移动数据之间切换或重置网络设置(“常规”>“重置”>“重置网络设置”>设置)。更新您的iOS版本:

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

users是什么文件夹? users是什么文件夹? May 28, 2021 pm 03:33 PM

users是电脑中的一个包含用户使用过程中产生的数据、程序内容以及文档、音乐等内容的文件夹。我们打开电脑中的资源管理器,就可以找到users文件夹了,有的电脑中也叫用户文件夹。

docker挂载目录权限问题怎么解决 docker挂载目录权限问题怎么解决 Feb 29, 2024 am 10:04 AM

在Docker中,挂载目录的权限问题通常可以通过以下方法解决:使用-v参数指定挂载目录时添加权限相关的选项。可以通过在挂载的目录后面添加:ro或:rw来指定挂载目录的权限,分别表示只读和读写权限。例如:dockerrun-v/host/path:/container/path:roimage_name在Dockerfile中定义USER指令来指定容器中运行的用户,以确保容器内部的操作符合权限要求。例如:FROMimage_name#CreateanewuserRUNuseradd-ms/bin/

watch4pro好还是gt好 watch4pro好还是gt好 Sep 26, 2023 pm 02:45 PM

watch4pro和gt各自具有不用的特点和适用场景,如果注重功能的全面性、高性能和时尚外观,同时愿意承担较高的价格,那么Watch 4 Pro可能更适合。如果对功能要求不高,更注重电池续航和价格的合理性,那么GT系列可能更适合。最终的选择应根据个人需求、预算和喜好来决定,建议在购买前仔细考虑自己的需求,并参考各种产品的评测和比较,以做出更明智的选择。

win11怎么修改用户文件夹名称?win11用户文件夹名称修改方法 win11怎么修改用户文件夹名称?win11用户文件夹名称修改方法 Feb 13, 2024 pm 12:36 PM

win11怎么修改用户文件夹名称?其实方法很简单的,用户们可以直接的打开组策略编辑器,然后进入到windows设置下的安全设置来进行操作就可以快速的完成。下面就让本站来为用户们来仔细的介绍一下win11用户文件夹名称修改方法吧。win11用户文件夹名称修改方法1、按下键盘“Win+R”组合键。2、在其中输入“gpedit.msc”回车打开组策略编辑器。3、展开“windows设置”下的“安全设置“。4、打开&l

See all articles