1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Is there a script, or way to insert codes into every file automatically?

Discussion in 'Programming' started by crumblepie, Oct 1, 2008.

  1. #1
    Is there a script, or a way to insert a snippet of code into every html and php file in a folder automatically?

    I don't want to make use of php include. I want the codes hardwritten individually into each page. Is there a way to do it?
     
    crumblepie, Oct 1, 2008 IP
  2. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #2
    You'd have to define youe question better. What are you specifically trying to do?
    If the pages and folder is on your server ..yes you can write to them and update them. why are you against the php include? you know its basically read by the browser as being part of the page once its there, right?

    your question was super vague so its hard to say for sure, but for what youre asking ..

    it still seems to me though that your easiest way to do this would be with an includes or at least a require php file. a line of code in all your webpages <?php include 'newcode_handler.php' ; ?>
    then have a seperate file called newcode_handler.php ..with all your code and then you just update that file and it appears on all your pages.

    But,
    If its absolutely necessary to do surgial implants to your pages (like if you have thousands of pages that you dont want to hand code one by one) ..the best strategy may be use combinations of fwrite.
    You will want to read the file, and have it read a specific number of lines and then to append and write the new code into that place in your file. That would be one of the only ways i can think of right now to go back and include new code to old files without any handlers or code on those pages already set up to accept incoming code.

    check out fopen and fwrite on Google ...look for some tutorials if i remember right, wc3schools had some decent tutorials back when.
    Using that that strategy though, you will still have to name all your files in that script.. in order to have the script find them by name and inject them.
     
    ezprint2008, Oct 2, 2008 IP
    crumblepie likes this.
  3. crumblepie

    crumblepie Well-Known Member

    Messages:
    2,612
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Thanks ezprint! +rep added :)
     
    crumblepie, Oct 2, 2008 IP