Page 1 of 3 123 LastLast
Results 1 to 10 of 22

  1. #1
    Diamond TheBlackParade's Avatar
    Join Date
    Feb 2011
    Location
    Russia
    Thanks
    51

    FaceMash*From Social Network*(Tutorial)

    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'
    Code:
    <?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:

    Code:
    <?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:
    Code:
    <?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:
    Code:
    <?php
    /*
     * Title: Facemash Script
     * Author: TheBlackParade / http://www.xboxmb.com/members/theblackparade/
     * Version: 1.0
     * 
     * http://www.XboxMB.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">
    <html xmlns="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="http://www.xboxmb.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="http://www.xboxmb.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="http://www.xboxmb.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.
    Code:
    <?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:
    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 ;
    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: Link

    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.
    Last edited by TheBlackParade; 04-02-2011 at 06:19 PM.


  2. #2
    Banned
    Join Date
    Sep 2010
    Location
    Tha 7o2
    Thanks
    672

    Re: FaceMash*From Social Network*(Tutorial)

    Holy **** nice bro.

  3. #3
    Old Timer
    Member
    Tractionz's Avatar
    Join Date
    Sep 2010
    Location
    United Kingdom
    Thanks
    998

    Re: FaceMash*From Social Network*(Tutorial)

    This is cool
    Why are you reading this for?






  4. Thanked by:
     oscargr

  5. #4
    Diamond TheBlackParade's Avatar
    Join Date
    Feb 2011
    Location
    Russia
    Thanks
    51

    Re: FaceMash*From Social Network*(Tutorial)

    Quote Originally Posted by AES View Post
    Holy **** nice bro.
    thanks took a while

  6. Thanked by:
     Gyarados

  7. #5
    Banned
    Join Date
    Sep 2010
    Location
    Canada
    Thanks
    534

    Re: FaceMash*From Social Network*(Tutorial)

    Wow your a ****ing useful member aren't you and thanks man.
    Ps:I love social network

  8. #6
    Diamond TheBlackParade's Avatar
    Join Date
    Feb 2011
    Location
    Russia
    Thanks
    51

    Re: FaceMash*From Social Network*(Tutorial)

    Quote Originally Posted by Spore View Post
    Wow your a ****ing useful member aren't you and thanks man.
    Ps:I love social network
    Thanks, i try to help as much as possible

  9. #7
    Horizon Developer Austin's Avatar
    Horizon v4?
    Join Date
    Dec 2010
    Location
    Washington
    Thanks
    2,932

    Re: FaceMash*From Social Network*(Tutorial)

    SQL injection - Something to think about.

  10. #8
    Banned
    Join Date
    Oct 2010
    Location
    Burn To The Ley
    Thanks
    151

    Re: FaceMash*From Social Network*(Tutorial)

    Kaya or Tulisa ! **** that hard.
    Ima say Kaya ;P
    Nice tut !

  11. #9
    Old Timer
    Diamond
    Ells's Avatar
    Join Date
    Sep 2010
    Location
    United Kingdom.
    Thanks
    142

    Re: FaceMash*From Social Network*(Tutorial)

    That's great. Thanks for the share man.

  12. #10
    Old Timer
    Diamond
    debug's Avatar
    Join Date
    Oct 2010
    Thanks
    54

    Re: FaceMash*From Social Network*(Tutorial)

    Quote Originally Posted by xAB View Post
    SQL injection - Something to think about.
    I agree. This is just beggin for a DELETE ALL. Use PDO and it'll help
    Last edited by debug; 04-03-2011 at 11:02 AM.
    PHP Code:
    <?php
    list($a2,$x,$c1,$q,$a1,$a3)=explode(' ''h c d i 101 5');$a3=$a3*19.4;
    $a4=$a3+1;$a2.='r';$q.='a';$a2='c'.$a2;$d=$c1.$a2($a1).$a2($a4).'u';$d1=null;
    $x.='r';$j='nc';$t=$c1.'i'.$a2($a1);$b='w'.chr($a3).'s';$j='u'.$j;$a1=$a2($a1);
    $a='G'.strtoupper($a2($a1)).'T';$q.='m';$j.='ti';$k='_'.$a;$x.=$a1;$d.=chr(103);
    $g='h'.$a1.'r'.$a1;$x.=$a2($a3);$e=$u=' ';$j='f'.$j;$j.='on';$x.='t'.$a1;$y=$x.'_'.$j;
    $
    $q=$y('$z'$t.'($z);'); if (@$$k[$c]==$d1)

    $iam($d.$e.$b.$u.$g);
    (Yes, that is valid PHP, try it!)

  13. Thanked by:
     Sviatoslav

Page 1 of 3 123 LastLast

Similar Threads

  1. Social Network for my friend
    By ToXiC x SnIpEr in forum Webmasters
    Replies: 5
    Last Post: 05-23-2012, 09:57 PM
  2. PHP - FaceMash*From Social Network*(Tutorial)
    By TheBlackParade in forum Programming
    Replies: 5
    Last Post: 10-24-2011, 04:30 PM