Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    877
    Thanks
    53
    Thanked 6 Times in 5 Posts

    batch file line addition

    Hi. I want to add a single line of code to the very top of many hundreds of php pages.

    Does anyone know of batch software that will do just that?

    Thanks!

    Terry
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Are you sure that there are hundreds of pages, or is there one script that
    dynamically generates those pages? Take this forum for example ... there
    are thousands of pages, but it's really only 1 script that makes all of them.
    There are really not thousands of pages.

  • #3
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    877
    Thanks
    53
    Thanked 6 Times in 5 Posts
    Yes, I'm sure.

    It appears that there is a single line of code that you can add to a php page that speeds up the loading of the page:

    Code:
    <? ob_start("ob_gzhandler"); ?>
    ...but you have to put it at the very top of each php page.

    It does work, but I have quite a few hundred pages that form part of a shopping cart (zencart) etc.

    Adding that single line of code by hand will be quite time-consuming.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    No, there is a way to do this without editing you're php files using .htaccess and ini directives.
    Assuming you're on Apache, you can put an auto_prepend call into you're .htaccess (which assumes you have AllowOverride for it).
    Code:
    php_value auto_prepend_file /path/to/autoprependfile.php
    Use a full path to keep from crazyness happening, or you can put it in a known include_path.
    With autoprependfile.php containing:
    PHP Code:
    <?php
    ob_start
    ('ob_gzhandler');
    ?>
    You won't need to auto append though, output buffering should flush itself at script termination.

    May I inquire as to why so many php files though? I mean, I've moved pretty much exclusively to OOP in PHP, yet my library itself is now about 107 class files. Even when I was procedural, I think the most files I've ever created for an entire site was 24 excluding configuration files. Management of that alone was a horrid task - I had known PHP for maybe 3 years at that point, so there was still a lot I didn't know about it (such as OO hah).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    tpeck (02-28-2010)

  • #5
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    If you do decide to amend the files, why not do it with a PHP script? Loop through dir (recursively if necessary), check if files are php (and any other logic you need), open and squirt in the extra line. 10 minutes php tops. If you don't have permissions then it might get harder, I would normally do a quick perl script on my local machine for a task like that but I don't have php installed locally, you might...

    Would also be quite easy in vbscript if you fancy it..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •