1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Delete old usernames when new usernames are submitted to .txt file

Discussion in 'Black Hat SEO' started by AnonLeo, Jan 11, 2014.

  1. AnonLeo

    AnonLeo Regular Member

    Joined:
    Nov 23, 2013
    Messages:
    362
    Likes Received:
    263
    Location:
    USA
    Hey,
    I will try to explain my situation as good as possible!


    Ok, let's say I have a .txt file on my website called "usernames.txt"
    In that file, there are usernames of my website members, every time a new member submits his username on my website, it will be saved in that "usernames.txt" file.

    Example on how the usernames.txt file looks like:
    jkdfhdskj@askjfsdjk.com
    sdofjeopjr@sdklfjdksf.com
    2314klnfjdks@dskjfds.com
    sdgkjnewjf@gmail.com
    dsfjsdkf@kksdfkds.com
    ect...


    Because that file gets big hourly, I have to delete the old usernames (the top = oldest) by myself.. And that sucks because when I am in school, I don't have access to my laptop so I can't delete the usernames and that causes problems on my server.. (It's hard for me to explain why, but it does make my website slower).

    What I want is a script or PHP code or something that automatically deletes the old usernames (Let's say the first 40 usernames at the top) and keeps the new one's in the file (Let's say the 30 usernames at the bottom) inside the "usernames.txt" file.
    OR
    a script that deletes the first usernames (at the top) every 30 minutes..So only the new usernames will be saved in the "usernames.txt"
    I know this question sounds wired, but the whole point is to make my server faster :)

    The file on my website is not called "usernames.txt" actually, but that is smiler to what the file is about.
    The file on my website saves the users Access Tokens (Facebook Graph thingy) but in the example I gave it is Usernames not Access Tokens. (Because most of the people don't even know what Access Token is, but hopefully everyone knows what Usernames are) :D

    Sorry for poor English
    And it's would be really really great if someone can help me :)
    Thanks!

     
  2. SeLecTeD

    SeLecTeD Regular Member

    Joined:
    Mar 21, 2010
    Messages:
    256
    Likes Received:
    37
    You can insert them into a mysql database :)
     
  3. pr250

    pr250 Junior Member

    Joined:
    Apr 7, 2010
    Messages:
    108
    Likes Received:
    23
    Code:
    <?php
    $X = "40"; // Number of lines to remove
    
    $filetoedit = "usernames.txt";
    $lines = file("$filetoedit");
    $lines = array_slice($lines, $X);
    
    // Write to file
    $file = fopen($filetoedit, "w");
    fwrite($file, implode('', $lines));
    fclose($file);
    ?>
    
     
  4. pr250

    pr250 Junior Member

    Joined:
    Apr 7, 2010
    Messages:
    108
    Likes Received:
    23
    Forgot to mention, if you need it to run every half an hour, you need to setup a cronjob in cpanel to call this php script. I wont go into detail on how to do this, there are thousands of tutorials on that.
     
  5. Nitros

    Nitros Power Member

    Joined:
    Jan 30, 2009
    Messages:
    573
    Likes Received:
    295
    As SeLecTeD suggested you should use mysql database for that. It would be faster. If you need some help with saving and reading that data from database you can contact me by pm and I will help ;)