Developing a Social Networking Website: PHP Scripts & Database Implementation for COMP 250, Study Guides, Projects, Research of Computer Science

A project for creating a social networking website similar to facebook using php scripts and a mysql database. The project includes scripts for login, creating accounts, editing accounts, setting status, searching for friends, adding and removing friends from the database, and logging out. Students will practice writing php scripts, using password verification, and session variables.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/19/2009

koofers-user-fwp
koofers-user-fwp 🇺🇸

10 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
MyFaceSpace
COMP 250 - Internet Development
Due Fri, May 1 at midnight
100 points
The goal of this project is to develop a social networking website that works similar to Facebook. This assignment
will give you practice writing PHP scripts that interact with a database, use password verification, and use session
variables.
Overview
The system will be composed of several scripts:
1. login.php – Handles logging in existing users.
2. create_account.php – Creates a new account for new users
3. edit_account.php – Edits account of existing users
4. index.php – The main page showing a complete profile and listing all friends
5. set_status.php – Sets the user’s status in the database
6. add_friends.php – Searches for friends
7. add_friend_db.php – Adds a friend to the database
8. remove_friend_db.php – Removes a friend from the database
9. logout.php – Logs user out
You may add more scripts if needed, but you should use the naming conventions above. A fully functional
prototype is accessible at http://taz.harding.edu/~fmccown/myfacespace/
Implementation
All the PHP scripts should be stored in your public_html/myfacespace director y and be accessible as
http://taz.harding.edu/~username/myfacespace/
The PHPs will access and store data in your MySQL database. The database tables have been created for you:
Users
username – varchar(45) The user’s username (key)
password – varchar(45) An MD5 hash of the user’s password
name – varchar(100) The user’s first and last name
status – varchar(250) The user’s status or personal message
updatetime – datetime The date and time when the status was set (format: 2009-04-02 13:35:00)
Friends
username1 – varchar(45) A username who befriends username2 (partial key)
username2 – varchar(45) A username who is befriended by username1 (partial key)
If bsmith adds jwhite as a friend, an entry in the Friends table would be username1=‘bsmith’ and
username2=‘jwhite’.
In order to connect to your database, place the following code in the .php files requiring database access:
$db = mysql_connect("taz.harding.edu", "username", "username")
or die("Could not connect : " . mysql_error());
mysql_select_db("username") or die("Could not select database");
where username is your username. Please make sure you are accessing your database only!
pf3
pf4
pf5

Partial preview of the text

Download Developing a Social Networking Website: PHP Scripts & Database Implementation for COMP 250 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

MyFaceSpace

COMP 250 - Internet Development Due Fri, May 1 at midnight 100 points

The goal of this project is to develop a social networking website that works similar to Facebook. This assignment will give you practice writing PHP scripts that interact with a database, use password verification, and use session variables.

Overview

The system will be composed of several scripts:

  1. login.php – Handles logging in existing users.
  2. create_account.php – Creates a new account for new users
  3. edit_account.php – Edits account of existing users
  4. index.php – The main page showing a complete profile and listing all friends
  5. set_status. php – Sets the user’s status in the database
  6. add_friends.php – Searches for friends
  7. add_friend_db.php – Adds a friend to the database
  8. remove_friend_db.php – Removes a friend from the database
  9. logout.php – Logs user out

You may add more scripts if needed, but you should use the naming conventions above. A fully functional prototype is accessible at http://taz.harding.edu/~fmccown/myfacespace/

Implementation

All the PHP scripts should be stored in your public_html/myfacespace directory and be accessible as http://taz.harding.edu/~ username /myfacespace/

The PHPs will access and store data in your MySQL database. The database tables have been created for you:

Users

  • username – varchar(45) The user’s username (key)
  • password – varchar(45) An MD5 hash of the user’s password
  • name – varchar(100) The user’s first and last name
  • status – varchar(250) The user’s status or personal message
  • updatetime – datetime The date and time when the status was set (format: 2009-04-02 13:35:00)

Friends

  • username1 – varchar(45) A username who befriends username2 (partial key)
  • username2 – varchar(45) A username who is befriended by username1 (partial key)

If bsmith adds jwhite as a friend, an entry in the Friends table would be username1=‘bsmith’ and username2=‘jwhite’.

In order to connect to your database, place the following code in the .php files requiring database access:

$db = mysql_connect("taz.harding.edu", " username ", " username ") or die("Could not connect : ". mysql_error()); mysql_select_db(" username ") or die("Could not select database");

where username is your username. Please make sure you are accessing your database only!

1. login.php

This script should ask for a username/password and contain a link to create_account.php for new users. When the page first loads, the cursor should be placed in the username field so the user doesn’t have to manually click in the field. This can be done with JavaScript:

This assumes the username text field is given the username ID. This form will submit its information back to itself. The following SQL query will be used to access the user’s information where bsmith is the username:

SELECT * FROM Users WHERE username='bsmith'

You’ll need to take the MD5 hash of the submitted password to check with the password hash extracted from the Users table. If the password is correct, you will need to set a session variable called “login” to “true”. This is how you will know if the user is logged in in the other scripts. You should also save the database information (name, status, and updatetime) to session variables so it is accessible to index.php. Finally, redirect the browser to the index.php page like so:

header("location: index.php");

If the username/password is incorrect, an appropriate error message should be given, and the user should be re- prompted for their username/password.

2. create_account.php

You should have already been given this script for use in an earlier assignment. It creates an account for a user. It should have a link to index.php after the account has been created. The script should redirect to login.php if the user is not logged in.

3. edit_account.php

You should have already created this script in an earlier assignment. It allows the user to edit their account. It should have a link to index.php after the account has been edited. The script should redirect to login.php if the user is not logged in.

4. index.php

This script is the main page where the user will see their profile and their friends’ profile. It may look something like the example on the right. The script should redirect to login.php if the user is not logged in.

This script will show the logged-in user’s profile if there is no “user” in the query string. Otherwise it will display the friend’s profile that matches the “user” in the query string.

The user can set their status by entering a string and clicking the Share button. The status string should be submitted to set_status.php which will update the database and redirect the user back to this page.

You should display how long ago the status was updated using a Facebook-like time status that indicates how long ago the time was in terms of seconds, minutes, hours, or days. A PHP function which implements this is available at from http://us.php.net/manual/en/function.time.php#89415.

5. set_status.php

This script should set the user’s status by taking the status that was submitted to it from index.php and updating the database like so:

UPDATE Users SET status='I'm doing great!', updatetime='$now' WHERE username='bsmith'

where $now is the current date and time. It can be obtained like so:

$now = date('Y-m-d H:i:s', time());

The script should then redirect back to index.php (using the header function).

6. add_friends.php

This script should allow the user to enter a search query for a friend’s name. The Users table can be searched for all matches like so:

SELECT * FROM Users WHERE name LIKE '%a%' ORDER BY name

which matches any name containing the letter “a”.

Those user who are not yet friends should be displayed with an “Add as Friend” link, but those that are already friends should be displayed with links that display their profiles.

The “Add as Friend” link should send the selected user’s username to the add_friends_db.php script like so:

http://taz.harding.edu/~ username /myfacespace/add_friend_db.php?user=dburks

where user contains the username of the person being friended.

7. add_friend_db.php

This script should grab the username from the query string and insert a new row in the Friends table to indicate a new friendship. For example, if dburks was being friended by bsmith, the insert statement would be:

INSERT INTO Friends VALUES ('bsmith', 'dburks')

After doing a successful insert, the browser should be redirected back to index.php.

8. remove_friend_db.php

This script will remove a friendship from the Friends table. It is invoked from index.php and contains the friend-to- remove’s username in the query string. To delete a friendship between bsmith and dburks, use the following SQL statement:

DELETE FROM Friends WHERE username1='bsmith' AND username2='dburks'

It is possible that bsmith and dburks are in the opposite columns of the Friends table, so you should check to see if performing this delete actually removed a row. If it didn’t, you’ll need to perform the following delete:

DELETE FROM Friends WHERE username2='bsmith' AND username1='dburks'

After a successful delete, the browser should be redirected back to index.php.

9. logout.php

This script should destroy the current session and present a link back to the login screen.

You will find it helpful to create a single header.php that is included in all your scripts. This header can include the site-wide style sheet and produce the heading at the top of each page.

Extra Credit: McChallenge

1% will be added to your final grade for modifying your add_friends.php to work with Ajax. Currently once you have clicked on “Add as Friend” your are redirected back to index.php. You should instead make an asynchronous call to add_friend_db.php which should return back “OK” if the friend was successfully added to the database. Then dynamically alter the DOM so the “Add as Friend” link is gone, and the person’s name and thumbnail are now links to the friend’s profile. This will allow a user to add many friends without leaving the screen.

Deliverables

Submit all your PHP files to Easel before the due date/time. Make sure your name, the date, and a description of what the file does are documented at the top of every file. Make sure you are accessing your database tables in your PHP pages and not anyone else’s.

Do not modify your PHP files on Taz after the due date. I will determine when the assignment was completed by each file’s timestamp. Make sure you have named your files according the specifications.

Your assignment should be accessible at: http://taz.harding.edu/~ username /myfacespace/

To dare is to lose your footing momentarily. To not dare is to lose yourself.

-Kierkegaard