The Facemash script

[update]

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.

Demo
Download

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

108 thoughts on “The Facemash script”

  1. 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

    1. 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 – yoursite.com/install_images.php.

      /Anders

      1. 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: http://unifacemash.site11.com

      2. 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. hey i have no idea how to do that :P im new to all this and how am i supposed to open the php files? i really need this explained.

  2. 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 facemash.ericaalbrigth.com — Thanks again!

    1. 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.

  3. 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?******’

  4. 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 (www.site.ru/rate.php?winner=2&loser=2)

    1. 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,
      /Anders

        1. Hey Anders,
          Where do I create the tables that are listed in in the readme.txt file? Pardon my ignorance, as I am new to php. A little dumbing down of the steps in the readme would be most helpful! I have the database set up and created a /images folder, I am just confused where the script is pulling things from.
          Thanks in advance,
          bc

          1. I’m kinda stuck at the same problem as Meu. I created a database but I have seriously no clue on how to add (or where) the tables. I’m also new to php.

    1. 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.

      /Anders

  5. 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 ?

    Thanks

  6. Hey,
    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.

    Thanks

    1. Im not completely sure what you mean: unnulling?
      The download is a zip file – you have to unzip it!?
      Thanks for commenting.
      /Anders

  7. 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?

    1. Hey man I dont have php knowledge either but I figured out how to install it. I can type up and email you step by step guide if you want maybe Admin can post it here for others to read :)

        1. how to put pictures and the rest togethere and pls explain in a little detail and help with this will be appreciated a lot and dammn neat work with the code but just tell me how to put it all together and reccomend a database and site uploader

  8. 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

  9. Hello
    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

    1. 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

      Tyler

  10. 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 0fees.net and im having MySQL version : 5.1.45 , as i am new to sql so i cannot understand what to do , please help :)

    Regards,
    Malik.

  11. 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

  12. 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)

    Tyler

  13. 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!

  14. 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

  15. Hello!
    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!

  16. 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 :) !

    1. 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

  17. 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: everfas.com instead of the everfas.com/facemash?
    Thanks.

  18. 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,
    Nikola.

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

  20. 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
    http://www.thewebhelp.com/php/scripts/image-upload-with-resize/
    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: “www.mydomain.com””

    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”
    thanks

  21. Hello
    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
    http://demo.facemash.gr/facemash_script.zip

    you can view a demo at
    http://demo.facemash.gr

    1.follow the original readme.txt

    2.you 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

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

  23. hi i am using wamp server. i installed the script.it 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

  24. 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 @andrejmkd23@hotmail.com

    Awesome Job

    Andrej

  25. 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.

  26. 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.

  27. 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…!

  28. 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”

  29. 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.

    Regards
    ospider from China

  30. 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

  31. 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 ?

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

    Help me please.

  33. 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.

  34. Hey,

    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?!

    Thanks

    Raphael Stolz

  35. Hey,

    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?!

    Thanks

  36. Hi admin i have download the site just a bit confused mate can you please do a YouTube video were you showing step by step on how to get it running please

  37. 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
    5.1.56 what i have to do. please help.

    Regards,

  38. Anders, I’m writting you to let you know that I followed your steps and it worked at the first try in my web server.. I’m running apache in old fedora box hosting my page from my home. It was fun to put all members of a charity club in panama (I’m from Panama) to test each other for the ugliest in the group :).

    I translated the page to spanish, and embededd it into wordpress through iframe.

    http://i.imgur.com/jbJCI.jpg

  39. Hey bro, just came up with the idea of doing the exact same thing a clone of Facemash… Then I was disappointed because you just did it. But that’s what let me to make more and more websites… Now I am finishing my third one.

    By the way, awesome script there ;)

    Twitter: alxhotel

  40. Hej Anders,

    Super fedt script, som bare kan bruges! Det er virkelig enkel og nemt, at opsætte. Jeg har dog et spørgsmål, som jeg håber du kan svare på. Jeg har lagt scriptet ud, lagt billeder ud og det hele virker fint. engang imellem… Nogle gange når jeg går ind på min side så kan jeg kune skifte billede én gang. Når jeg herefter klikker på billederne så går den til rate.php bla bla bla og tilbage til forsiden, men billederne skiftes ikke ud.

    Kender du problemet og har du en evt. løsning på dette? :-)

    De bedste hilsner,
    Kasper Torp

  41. It’s incredible easy to cheat isn’t it? You just copy a link with winner=’id’ as many times as you want.
    I am making my own facemash-alike script for a small community which is full of geeks ;) so the possibility of cheating is about 1.
    Here’s what I try to implement. Before displaying two competitors I put two randomly taken from SQL id’s in PHP $_SESSION and call them like “left id” and “right id”. And my links look like rate.php?winner=left or winner=right. After submit I destroy session so when user tries to copy and paste that address in address bar he gets an error because the session is empty.
    But this is just the first step to improve security. I figured out that user can just sit and refresh the page until he gets his own photo than vote for it. To prevent this you should check $_SESSION before generating the page. If it’s not empty that means the user hasn’t yet chosed one of a given pair. So I kinda force user to make a choice. When he hits F5 he gets the same options.
    BUT! User can clear cookies and cheat anyway. And I know he will. So I also plan to add IP check for more security. Last given pair of options will be stored not only in _SESSION but in database along with IP as well. But even that’s not enough though because user can use proxies to cheat. Athorization with social account is the most reliable option but I it seems a bit steep.
    If you build an app for facebook it looks kinda easier to improve security using APIs.

    1. I just tought maybe it’s a good idea to aks user to enter captcha once if the session is empty. You know, for more security. It’s a serious business after all :)

  42. Hey.. firsr off love your script, it’s amazing. Wondering if its possible to have the images pulled from seperate folders.

    Example. One side photo is from folder X and the other side is folder Y

  43. Still w8ng for an update on ur script..and plz also add keyboard support..i mean if a user presses right arrow key right image is selected.

  44. Hello Anders
    I have setup the database tables, but i can’t figure out who to “upload” the images! Can you please tell it step by step. I use XAMPP and phpMyAdmin.

    /Emil

  45. Thank you for sharing the great work.
    I followed the instruction in the “read me” file, but still there is no images loaded in the page, and some codes like wins?> and loser ?> are displayed below the space where image is expected. Please help.

  46. Hi,

    Nice work on writing the elo system into a class. As you probebly notest, it doesn’t quite work as you expect it to work. That is because the ELO system’s take on the problem is like using (22 / 7) as PI, it works, but not with great accuration.

    I tried to crack problem, and wrote my own algeritm and I think I succeeded. The main problem is that the ELO system calculates a expectation based on just the wins and losses of only the 2 players of the battle, while the did the battle.

    I tried to explain my algeritm on this website: http://onlinekitesurfcompetition.com/About.aspx

    Could you take a look let me know what you think?

    Thanks Willem

  47. I like the valuable information you provide in your articles.
    I’ll bookmark your blog and check again here regularly.
    I’m quite sure I will learn many new stuff right here!
    Best of luck for the next!

  48. When I try to execute,
    This comes:
    SQL query:

    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;

    MySQL said: Documentation
    #1064 – 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 ‘’1500′,
    wins int(10) unsigned NOT NULL default ’0′,
    losses int(10)’ at line 4

    What should I do now?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">