Modification to 150+ files

Discussion in 'Programming' started by xxsAm, Aug 7, 2007.

  1. #1
    I need a script that will be able to add a snippet of code to the top of 150 or so php files(/home/*/public_html/index.inc.php) for multiple users as I do not want to have to go in via ftp and do this manually. I can pay $5 as I think this would be something simple to make.
     
    xxsAm, Aug 7, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    <?php
    
    // array of usernames, or however you want to populate the list
    $users = array('user1', 'user2', ...); 
    
    // Code, use \n to add a line break
    $code = "<?php\n// your code\n\?>\n";
    
    foreach ($users as $user) {
        $fp = fopen("/home/$user/public_html/index.inc.php", 'r+');
        fwrite($fp, $code);
        fclose($fp);
    }
    
    ?>
    
    PHP:
     
    krt, Aug 7, 2007 IP