If you have seen the movie; Social Network, about the creation of facebook at the events surrounding it, you will know that Mark created a website called FaceMash, where would rate girls based on their looks, Today i’m going to show you how to make your own FaceMash.
First You are going to need a program called ‘Notepad++’, i will try and get a download link as soon as i can, but until then, just google Notepad++.
Now once you have downloaded Notepad++ open it and it will open a new document. Type/paste the following into Notepad++ and save it as ‘Rate.php’
<?php
include('mysql.php');
include('functions.php');
// If rating - update the database
if ($_GET['winner'] && $_GET['loser']) {
// Get the winner
$result = mysql_query("SELECT * FROM images WHERE image_id = ".$_GET['winner']." ");
$winner = mysql_fetch_object($result);
// Get the loser
$result = mysql_query("SELECT * FROM images WHERE image_id = ".$_GET['loser']." ");
$loser = mysql_fetch_object($result);
// Update the winner score
$winner_expected = expected($loser->score, $winner->score);
$winner_new_score = win($winner->score, $winner_expected);
//test print "Winner: ".$winner->score." - ".$winner_new_score." - ".$winner_expected."<br>";
mysql_query("UPDATE images SET score = ".$winner_new_score.", wins = wins+1 WHERE image_id = ".$_GET['winner']);
// Update the loser score
$loser_expected = expected($winner->score, $loser->score);
$loser_new_score = loss($loser->score, $loser_expected);
//test print "Loser: ".$loser->score." - ".$loser_new_score." - ".$loser_expected."<br>";
mysql_query("UPDATE images SET score = ".$loser_new_score.", losses = losses+1 WHERE image_id = ".$_GET['loser']);
// Insert battle
mysql_query("INSERT INTO battles SET winner = ".$_GET['winner'].", loser = ".$_GET['loser']." ");
// Back to the frontpage
header('location: /');
}
?>
You can miss out the comments if you wish, but as this is to help people learn, i will leave them there, if you have not already done so, save this as ‘Rate.php’
Now go to ‘File’>‘New’ to open a new document.
In the new document type the following:
<?php
// Mysql settings
$user = "";
$password = "";
$database = "";
$host = "";
mysql_connect($host,$user,$password);
mysql_select_db($database) or die( "Unable to select database");
?>
And save it as ‘mysql.php’
Open another New Document and type/paste the following into it:
<?php
include('mysql.php');
if ($handle = opendir('images')) {
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
if($file!='.' && $file!='..') {
$images[] = "('".$file."')";
}
}
closedir($handle);
}
$query = "INSERT INTO images (filename) VALUES ".implode(',', $images)." ";
if (!mysql_query($query)) {
print mysql_error();
}
else {
print "finished installing your images!";
}
?>
And save this as ‘install_images.php’
Open yet another New Document and type/paste the following:
<?php
/*
* Title: Facemash Script
* Author: TheBlackParade / [https://www.wemod.com/members/theblackparade/](https://www.wemod.com/members/theblackparade/)
* Version: 1.0
*
* [https://www.wemod.com](https://www.wemod.com/)
* Performance rating = [(Total of opponents' ratings + 400 * (Wins - Losses)) / score].
*/
include('mysql.php');
include('functions.php');
// Get random 2
$query="SELECT * FROM images ORDER BY RAND() LIMIT 0,2";
$result = @mysql_query($query);
while($row = mysql_fetch_object($result)) {
$images[] = (object) $row;
}
// Get the top10
$result = mysql_query("SELECT *, ROUND(score/(1+(losses/wins))) AS performance FROM images ORDER BY ROUND(score/(1+(losses/wins))) DESC LIMIT 0,10");
while($row = mysql_fetch_object($result)) $top_ratings[] = (object) $row;
// Close the connection
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)">
<html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Facemash</title>
<style type="text/css">
body, html {font-family:Arial, Helvetica, sans-serif;width:100%;margin:0;padding:0;text-align:center;}
h1 {background-color:#600;color:#fff;padding:20px 0;margin:0;}
a img {border:0;}
td {font-size:11px;}
.image {background-color:#eee;border:1px solid #ddd;border-bottom:1px solid #bbb;padding:5px;}
</style>
</head>
<body>
<h1>FaceMash</h1>
<h3>Were we let in for our looks? No. Will we be judged on them? Yes.</h3>
<h2>Who's hotter? Click to choose.</h2>
<center>
<table>
<tr>
<td valign="top" class="image"><a href="rate.php?winner=<?=$images[0]->image_id?>&loser=<?=$images[1]->image_id?>"><img src="https://www.wemod.com/images/<?=$images[0]->filename?>" /></a></td>
<td valign="top" class="image"><a href="rate.php?winner=<?=$images[1]->image_id?>&loser=<?=$images[0]->image_id?>"><img src="https://www.wemod.com/images/<?=$images[1]->filename?>" /></a></td>
</tr>
<tr>
<td>Won: <?=$images[0]->wins?>, Lost: <?=$images[0]->losses?></td>
<td>Won: <?=$images[1]->wins?>, Lost: <?=$images[1]->losses?></td>
</tr>
<tr>
<td>Score: <?=$images[0]->score?></td>
<td>Score: <?=$images[1]->score?></td>
</tr>
<tr>
<td>Expected: <?=round(expected($images[1]->score, $images[0]->score), 4)?></td>
<td>Expected: <?=round(expected($images[0]->score, $images[1]->score), 4)?></td>
</tr>
</table>
</center>
<h2>Top Rated</h2>
<center>
<table>
<tr>
<? foreach($top_ratings as $key => $image) : ?>
<td valign="top"><img src="https://www.wemod.com/images/<?=$image->filename?>" width="70" /></td>
<? endforeach ?>
</tr>
<? /* Remove this to see the scoring
<tr>
<? foreach($top_ratings as $key => $image) : ?>
<td valign="top">Score: <?=$image->score?></td>
<? endforeach ?>
</tr>
<tr>
<? foreach($top_ratings as $key => $image) : ?>
<td valign="top">Performance: <?=$image->performance?></td>
<? endforeach ?>
</tr>
<tr>
<? foreach($top_ratings as $key => $image) : ?>
<td valign="top">Won: <?=$image->wins?></td>
<? endforeach ?>
</tr>
<tr>
<? foreach($top_ratings as $key => $image) : ?>
<td valign="top">Lost: <?=$image->losses?></td>
<? endforeach ?>
</tr>
*/ ?>
</table>
</center>
</body>
</html>
And save it as ‘index.php’
Now open a New Document (For The Last Time) And type/paste The following into it.
<?php
// Calculate the expected % outcome
function expected($Rb, $Ra) {
return 1/(1 + pow(10, ($Rb-$Ra)/400));
}
// Calculate the new winnner score
function win($score, $expected, $k = 24) {
return $score + $k * (1-$expected);
}
// Calculate the new loser score
function loss($score, $expected, $k = 24) {
return $score + $k * (0-$expected);
}
?>
And save it as ‘functions.php’
Now weve finished the coding, we’ll move onto the next part, where we will actually get it to work. You will need to upload these files we created to a File Hosting site, i am going to use AlterVista to demonstrate this(As It Is My Favorite Hosting Site)
Go to http://www.altervista.org
and then type in the name you that you want to call your website:

and click prosegui
Now fill in the sign-up form.
And then click the big arrow.
Nome=Name
cognome=Surname
Sesso=Gender
Anno Di Nascita= Date of Birth
Nazione=Nationality
Provincia=Province
Codice di sicurezza=Security Code
Ricopia Codice=Copy Code
Now Visit your Email and open the email the send you and visit this link.
(Not that exact link, the one they send you in the email.)
You will now be taken to your new website and it will look like this:
Now Hover over Publish and select ‘File Managment’
You will be taken to this screen, you need to delete Index.html before you continue(By clicking the Red cross next to it.)
Now click on 'Upload Files.
and you’ll be taken to this page:
now click on ‘select files’ and upload the ones i upload
(Dont upload _ReadMe)
They will now be here:
[spoil]
Now create a folder called ‘Images’ but dont put anything in it yet
Now hover over’AlterSite’ and click on ‘Resources and Upgrades’
You will now be taken to this page:
and click on the ‘Database’ tab
You will be taken to this page:
Select ‘Class 4’ and ‘Confirm Modifications’
Now go to ‘Tools’ Then PhpMyAdmin
It will open a page like this
Now go back to the email you received the activation link in and get your username and password
Now type them in the box that comes up for PhpMyAdmin.
Click on your username at the side(May take a few moments to appear.)
Now click on the ‘SQL tab’
Now in the box that comes up type the following:
CREATE TABLE IF NOT EXISTS `battles` (
`battle_id` bigint(20) unsigned NOT NULL auto_increment,
`winner` bigint(20) unsigned NOT NULL,
`loser` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`battle_id`),
KEY `winner` (`winner`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `images` (
`image_id` bigint(20) unsigned NOT NULL auto_increment,
`filename` varchar(255) NOT NULL,
`score` int(10) unsigned NOT NULL default '1500',
`wins` int(10) unsigned NOT NULL default '0',
`losses` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`image_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
And click ‘Go’
It will say ‘Your SQL query has been executed successfully’
Now click on ‘publish’ Then ‘File Management’ and click the Pencil next to ‘MySQL.php’
and where it says
$user = “”;
$password = “”;
$database = “”;
$host = “”;
Type in your User, Password,Database and host, so mine would be
$user = “facemashxboxMB”;
$password = “”;
$database = “my_facemashxboxMB”;
$host = “localhost”;
and Yours would be:
$user = “(Your Username)”;
$password = “”;
$database = “my_(Your Username)”;
$host = “localhost”;
(Leave Password Blank)
now save
Now click on the images folder, then Upload Files then Upload the images you want the users to choose between.
Now got to ‘Publish’ Then ‘File Managment’
Then Click Parent to go back to the main directory.
Now double click on ‘install_images.php’
and you should get this screen:
Now you’r FINISHED! Time to try it out!
Simply Double click on Index.html to test it out, if you want to share it with your friends, the link will be: (Username).altervista.org/
Finished product: FacemashCelebrity
Image of Finished Product:
If you have any questions or if you need help, please PM me or leave a reply below, i’l be happy to help.
*I am unsure if the spoilers for the images are going to work, if they dont i’ll fix them in the morning, i’m tired.