Anders Moefelt

The Facemash script


I’ve been updating the script for a more secure rating procedure etc. It’s not packed yet for download – but I’ve made a new Facebook App which uses the new Facemash Class – check it here.

After having seen The Social Network I got the urge to look further into the ratingmodel they used to rate girls on Facemash.

After som research I found out that the model is called the ELO ratingsystem. It was developed by Arpad Elo and is a way to calculate the differences in strenght between 2 players – like in Chess. It’s impossible to calculate the exact outcome of any 2 player game but looking on wins, losses and draws against other players you can calculate the expected outcome by using the ELO system. You can read much more about the mathematical details on Wiki.

It was quite easy setting up the script – like imposed in the movie – and the power and possibilities of the script by far exceeds the efforts setting it up. The script is written in PHP/MySQL. Read the _readme.txt in the zip for installation guides.


Please leave a comment if you’ve implemented it somewhere, added something or just think it’s great.


  1. Vlad says:

    Thanks man. Great work. I love your script)

  2. Daryl says:

    hey thanks for the script. Can you give me a step by step guide to setting it up? I am kinda new to this (mysql, php, apache). I have read the _readme.txt file. I did part of what it says. I don’t know how to send images to the database. Please help. Thanks

    • admin says:

      Hi Darryl,

      Place all the images you want up for contest and run the page: “install_images.php” from your site to install all images from your folder into your database –


      • Daryl says:

        Hey Anders. Its Daryl again.
        Many thanx again for da script. I got it up n running. My site’s been live for more than a month n has received a good number of hits. I added a few features of my own such as an admin area where i get to upload more photos, see how many site hits and see how many users are online. Also, visitors are allowed to choose a cateogory between males and females. My site is the my university’s version of facemash. I sorta hacked the facebook profiles of people who go to my uni, the university of zambia, and downloaded their profile pics.
        The best part is no one cared that i used their photos. They actually love the site n think of it as brilliant, which is all thanx to u.
        Check it out here:

      • Brady Moseson says:

        Hi Anders is there a way i can get in contact with you? I am using your script in creating my own Facemash but it doesnt seem to be working because sometimes it only loads one of the pictures on the site without the other. I would really appreciate your support with this issue as i am looking forward to proceeding with this creative idea. Thank you for the time.

  3. Erica A. says:

    Great script! This is exactly what I was looking for. My website gets thousands of visitors a day ever since the Social Network came out. I’m using your script for my “Prettiest Facebook Friend” Contest. There are 10 finalists and the script is up at — Thanks again!

    • admin says:

      Hi Erica,

      Wow – many thanks – I didn’t see that one coming while doing the script :-)

      Kind regards,


    • Brady Moseson says:

      Hi erica i was thinking about doing the same thing with the script by rating girls in my high school. Is there a possibility of getting in big trouble for all of this? Again, i am a high school student.

  4. Vladislav E. says:

    Great! But.
    One small problem when you select an image. Link can open in a new window and we can vote for the same image indefinitely.
    Then it’s better to make link like this: javascript:self.location.href=’rate.php?******’

  5. Vladislav E. says:

    Annnd. .. In rate.php better to add a check for something with which the page came from. But something else may be in the address bar just enter (

    • admin says:

      Hi Vladislav,
      Thanks for your comments!
      I know there’s much room for improvements – the script was made very fast just to try out the rating method.
      I’ll make an update sometime in the future – no doubt.

      Best regards,

  6. bc says:

    Hey there. Not receiving the download email. Any thoughts?

  7. Alexonfire says:

    Nice, but need an update, really. Any plans on that?

    • admin says:

      Hi Alex,
      I’m currently writing an update with a lot more fraud prevention etc. – not sure when its finished though – but I got my own facebook project which is gonna use the script :-)
      I’ll keep you posted when I put it up for download.


  8. Ruslan says:

    What i can to write there????
    Thanks a lot of

  9. Brian says:

    Hey Dude what’s up? Im from argentina for that my english its bad.
    I have a problem whit you facemash script.
    How I contact you for MSN or Facebook for help me?
    When Facemash Script 2.0 ?


  10. Nathan says:

    I really need help un-nulling this code. Can you send me your code or something because I have no idea how to un-null it. Maybe you can tell me instead.


  11. bc says:

    Got it up and running at . Thanks so much!

  12. meu says:

    hey great job! i saw your script working in above mentioned website! but users like me dont have php knowledge a much.. so pls can you make a video tutorial?

  13. Conor Reid says:

    Thanks so much! Your script is kind of amazingly awesome, and I used it to build my site. You can view it here: Thanks again!

  14. Kamir says:

    Thanks for sharing such great work. I read the ‘read me’ file and did as told in it, but still there are no images loaded in the page and some codes like loser ?> wins?> are displayed below the space where image is expected. Again thanks

  15. Kolt says:

    Thank you so much for sharing this script. It is very simple but can be a lot of fun!! There is one thing I noticed about it:

    I was wondering if its possible to update the folder of pictures without going over the pictures that are already in there? I mean when I upload a few new photos to the server and type /install_images it will load up all images again and the original ones will be doubled in the database…

    Also do you know how to give a tool for visitors to upload their own photos? It seems like its a good idea to let them add their stuff but on the other hand I think they should not be able to post without me first checking them. I do not want to have some stupid pictures uploaded by pranksters…

    I hope you will find a minute to help me. After I solve this issue I hope to have my Mash operational this weekend to share with people here :)

    Thanks a lot

    • Tyler says:

      Hey Koult, I’m not sure about the first part but I wanted to comment on the second point of how to get your fans to uplad their own. create an email, and or storage dump on your site, and tell them to upload their pictures and names of ppl there and you pick the best ones


    • dg says:

      2 great points here! Any solution to the double loading of images already in the database??

  16. Malik says:

    Dear Admin,
    I downloaded the script and have done everything according to readme.txt file ,
    but when i execute install_image.php it says :-

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 1
    I am using and im having MySQL version : 5.1.45 , as i am new to sql so i cannot understand what to do , please help :)


  17. sad says:

    I really don’t understand the steps, can u just show us how to do that in some sort of movie?
    I am not familiar with php so plz help

  18. Tyler says:

    I desperately want this addition to my website but don’t know how to go about even working with it. Can I please get assistance?

    I downloaded the .zip file but don’t know how to go about using/working with any of the stuff I just downloaded. please help, I will cite who helped in my site (free advertising)


  19. meu says:

    Hey anders,
    this is meu again. any plans about the video tutorial from the beginning? please do it,, it ll be very much helpful for people like me!

  20. John says:

    Quick question, is there a way to use this script to have users add pictures to the voting pool? i see the question has been asked before, but back in 2010

  21. Bulat Garipov says:

    I have the same problem as Kolt. Some pictures are doubled when I upload few new photos. Some pictures don’t open, I don’t know why. Please, somebody help me!

  22. nino says:

    hi bro is it a very nice work ..but i am have a problem the score never changes. even if i pick a picure then it doesnt say won: 1

    Thanks för the script again :) !

    • nino says:

      so for all these typos…

      hi bro its a very nice work ..but i´m having a problem with the score ,its never changes. even if i choose a picure then it doesnt say won: 1 or anything?

      Thanks för the script again

  23. sam says:

    Hey, can i use this script on my site?
    Also – awesome work.

  24. Pavel Shimansky says:

    I don’t understand how to make MySQL database. Please help.

  25. Pavel Shimansky says:

    When I run I get a message “Table ‘**********.images’ doesn’t exist”.
    What should I do?

  26. Blur says:

    mate can u teach me how to config the php table

  27. meu says:

    MAN! atlast i worked it out. THANKS A LOT MAN, I learned Php and mysql for that .. you rock :D

  28. dg says:

    Great script…anyway to have visitors upload their own photos??

  29. Yugene says:

    Hi, really thanks for the script. It is amazing. =D

    But, may I ask why that when I click on the picture to vote, it will jump back to my original domain: instead of the

  30. Nikola says:

    Hello Anders,

    tnx for such a useful script :) I have many ideas based on your script. It will help me a lot :)

    Unfortunately, I’m having problems when i try to execute install_image.php :(

    It says:

    Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

    Could anyone help me, please?

    Tnx in advance :)

    Best regards,

  31. mitchell says:

    how do you “2) setup your database – look in the file: mysql.php
    3) execute this SQL to setup your database tables:”?

  32. Jeff C. says:

    I like the script. Just installed it at

    Any suggestions on how to go about setting up something along the lines of a Stats page, so that users could see the win-loss records of all of the images?

  33. lefaek says:

    Hello admin
    Many thanks for your work. Your script is good and simple
    I agree with Kolt.
    User should be able to add their own images
    Maybe we can all help with this.

    i used this script
    and set image width/height to “disabled” and to the resolution i want (e.g. 400×400) so all images are resized to same dimensions
    after the user click upload, his image will appear and then i add a button (at submit.php) redirecting to install_images.php and change install_images.php bottom code from “…your images have uploaded…” to “Location header: “”"

    so the image is added to the database. But the problem is that all images are added again, so i have dublicated images
    I am trying to re-configure install_images.php so it will add only the last image
    I have to make it “call” the image valiable from submit.php (submit.php is from the upload image script) or read old files and install only new files
    any help with that?

    please don’t hesitate to contact me at “info [at] facemash [dot] gr”

  34. lefaek says:

    first of all many thanks to the admin and creator of this script. It is very good and simple

    i have found a upload image script and insert it to facemash, so users can upload their own images

    you can download the script here

    you can view a demo at

    1.follow the original readme.txt must first upload images to server>run install_images.php and then use the “..upload your image..”

    3.don’t run install_images.php again or you’ll have dublicated entries.

    with the submit.php (“upload your images link”) you won’t get dublicated entries. only the last image is inserted to the database

  35. vignesh says:

    hi.its really awesome. but its not working in my localhost. i am using wamp showed unidentified index error. i rectified it. but yet the image not loading. pls help me….

  36. vignesh says:

    hi i am using wamp server. i installed the showed undefined index error. i rectified by editing php ini file. after that also the script does not show the images to rate. please help me. please

  37. Dennis says:

    Dear Anders,

    This script really rocks. But I do not got this working… Little strange in my opinion.
    I get this:

    Where does the problem lay, at me?

    Please tell me!

  38. Andrej says:

    Hey Andres,

    I’m a beginner to this php,mysql things. And by beginner i mean 0% of knowledge because i have always worked on design and visual stuff. So I;m asking can you send me a more in depth tutorial/readme on how to do these things. If you can please send it

    Awesome Job


  39. Tignass says:

    Hi, thanks a lot for this script.
    I did a website that I called Film Smash to rank films, it worked pretty well.
    But I still have a question :
    How do you do to avoid to go on the page you saw before. Because now if you go back you’ll have the same fight, then you can spoil the ranking as you want.

    Thanks a lot again.

  40. Rohan says:

    I am getting everything from the readme file right, but as i open the page in my localhost..i cant see the images..although i see those images loaded in my database..still they are not reflected on the website.

  41. ospider says:

    Thanks,dude,I just finished watching the Social Network film

  42. vignesh says:

    hi i uploaded.but the images are not coming.please help me.. check it at

  43. Randika says:

    Thanks buddy,I’s looking for this,to examine as a self study I’ll look into the code and come back later,take care…!

  44. zahid says:

    Love the script! But its not working properly for me..

    When i click the image I want to rate, nothing happens…

    Please check it at THANKS!!

  45. Martin says:

    Thanks for the script! Any news on when you will release the next update you refer to in your last post dated from Nov 2010? In particular: “updating the script for a more secure rating procedure etc”

  46. ospider says:

    There are two bugs in your script:
    First,when it’s installed in a sub-directry of some website,the viewer will be brought back to the homepage of the website by clicking on the images;
    Second,It’s a little confusing for MySQL/PHP beginners to config the “mysql.php”,more terribly,the varible $host can only be set as “localhost”,which consumes me lots of time to figure it out.

    ospider from China

  47. co22wen says:

    hey sorry i know this is stupid that I’m asking you this but I’m new to this HOPEFULLY you’ll help me, what do you mean by setup your database?? I’m really new to this stuff and would like to create one for school

  48. tydy says:

    HI !
    Your script is great but i have a trouble, all picture cant be displayed !

    this error

    Notice: Undefined variable: images in C:\Program Files\EasyPHP-5.4.0beta2\www\fm\index.php on line 71

    i work in localhost becaus im just testing this scirt

    Why the cant be desplayed ?

  49. Alex Popescu says:

    Hello,help me install please.I read the readme but i can’t .! here is my website.Help me.
    Where I need to put this code :
    `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`)

    `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`)

    Help me please.

  50. ER@432 says:

    Anyone having problems, just make a site using a free hosting service, and there shouldn’t be any problems. I had problems too with localhost, but none now.

  51. Raphael says:


    Can you please make a video-tutorial or something about your script. Because I don’t understand what i have to do at the third step in your readme.txt file!

    Can you help me please?!


    Raphael Stolz

  52. Raphael says:


    Can you please make a video-tutorial or something about your script. Because I don’t understand what i have to do at the third step in your readme.txt file!

    Can you help me please?!


Leave a Reply