Making a php script to edit another php script.

Discussion in 'PHP' started by keeganray, Feb 24, 2010.

  1. #1
    I am trying to access my php script and replace a link that is in the script with a new link. I know the basics of fopen and fwrite, but I don't know how to get the code to overwrite a specific line in my code.

    Thanks,

    Keegan
     
    keeganray, Feb 24, 2010 IP
  2. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #2
    You cannot just overwrite 1 line. Make a script that loads the other script in a textarea box. edit it, and click the submit button. The code for submit could be:
    
     $data= $_POST[textarea_code];
    if (get_magic_quotes_gpc()) { $data=stripslashes($data); }
    $f= fopen('file.php', 'w'); fwrite($f, $data); fclose($f);
    
    Code (markup):
    That's a basic code with no security/required checks, but I'm sure you can develop on it.
    The stripslash is done to remove any \ that your server might have added to the posted data based on server settings.
    Thanks :)
     
    JEET, Feb 24, 2010 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    If you want it done without your writing anything, read the file and write out a new file. When you get to the line with the link write the new link, not the old one. Then delete the original file and rename the new one to the old name.
     
    Rukbat, Aug 22, 2011 IP