Table of Contents
Users you're following
Sorry, could not connect to database.
List of Users
Home Backend Development PHP Tutorial 小型 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>
Copy after login


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 );?>
Copy after login

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>
Copy after login



?

?

<?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 );	}}?>
Copy after login


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" );?>
Copy after login


<?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" );?>
Copy after login



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

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

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

What folder is users? What folder is users? May 28, 2021 pm 03:33 PM

Users is a folder in the computer that contains data, program content, documents, music and other content generated during the user's use. When we open the resource manager in our computer, we can find the users folder, which is also called the users folder in some computers.

How to solve the problem of docker mounting directory permissions How to solve the problem of docker mounting directory permissions Feb 29, 2024 am 10:04 AM

In Docker, the permission problem of the mounting directory can usually be solved by the following method: adding permission-related options when using the -v parameter to specify the mounting directory. You can specify the permissions of the mounted directory by adding: ro or :rw after the mounted directory, indicating read-only and read-write permissions respectively. For example: dockerrun-v/host/path:/container/path:roimage_name Define the USER directive in the Dockerfile to specify the user running in the container to ensure that operations inside the container comply with permission requirements. For example: FROMimage_name#CreateanewuserRUNuseradd-ms/bin/

How to change the user folder name in win11? How to modify the name of win11 user folder How to change the user folder name in win11? How to modify the name of win11 user folder Feb 13, 2024 pm 12:36 PM

How to change the user folder name in win11? In fact, the method is very simple. Users can directly open the Group Policy Editor, then enter the security settings under Windows Settings to perform the operation, and the operation can be completed quickly. Let this site carefully introduce to users how to change the name of win11 user folder. How to modify the name of win11 user folder 1. Press the "Win+R" key combination on the keyboard. 2. Enter "gpedit.msc" and press Enter to open the Group Policy Editor. 3. Expand "Security Settings" under "Windows Settings". 4. Open&l

What is the folder users What is the folder users Feb 21, 2023 pm 03:16 PM

users is the user folder, which mainly stores the user's configuration files; the User folder contains data generated during the user's use, program content, documents, music and other content. The users folder is an important folder in the Windows system and cannot be deleted at will; it saves a lot of user information. Once deleted, data will be lost, and in severe cases, the system will not start.

See all articles