Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2002
    Posts
    58

    PHP Auto Pre-/Append

    A friend of mine needs hosting for a small personal website, so I offered him a subdomain on my server. There are just a few things I want to do so he can't mess up my webserver.
    Ofcourse I will disable the use of .htaccess, I also disabled PHP files from being parsed. But I still have a few questions...

    Are there any other important things I should disable?

    And another question regarding PHP Pre-/Appending, I want to rewrite all his outgoing links so that they open in a frame including a banner, but I don't want his HTML files to be changed. I figured the easiest way was by setting up a rewrite script that'll rewrites every page. But by using the following in my httpd.conf:
    Code:
    php_value auto_prepend_file header.php
    php_value auto_append_file footer.php
    Only *.php files get rewritten when PHP is enabled. When I disable PHP for his subdomain nothing changes, even when I place the header and footer in a directory that do parse PHP.
    So my second question is: "How can I get a PHP script to rewrite every requested HTML page for his subdomain and at the same time disable PHP?"

  2. #2
    Join Date
    Mar 2002
    Location
    London & Kent, UK
    Posts
    372
    I want to rewrite all his outgoing links so that they open in a frame including a banner
    How nice. I wonder how long you'll keep your friend

    Presumably they're not advertising banners for his site?
    Real-time intrusion protection and error reporting for PHP sites ioncube24.com
    Software protection for website owners and PHP developers ionCube PHP Encoder

  3. #3
    Join Date
    Oct 2002
    Posts
    58
    No, I won't add any banners or alike to his site.

    Does anybody have a real suggestion to help me out?

  4. #4
    Join Date
    Mar 2002
    Location
    London & Kent, UK
    Posts
    372
    No, I won't add any banners or alike to his site.
    You missed the point in my comment. It's the evil hotmail trick and not that nice a thing to do. If a site has links to some external site, the user following the link doesn't expect or want the page to have some banner on the top, and it can break navigation and cause other problems.

    But how about this anyway. Write a new buffer handler and parse and modify the buffered contents before flushing.

    output_buffering = on
    output_handler = somefunction

    might get you somewhere.
    Last edited by phpa; 11-16-2002 at 08:01 PM.
    Real-time intrusion protection and error reporting for PHP sites ioncube24.com
    Software protection for website owners and PHP developers ionCube PHP Encoder

  5. #5
    Join Date
    Oct 2002
    Posts
    58
    Hmm, I'll consider that. But how would it break navigation? I'm not using a script like "redirect.php?site=somesitehere.com", I know if the page to redirect to uses variables too that would break navigation. I'm using something like "redirect.mydomain.com/http://somesitehere.com?viariable=ok"

    Anyways, your suggestion. I was thinking about using output buffering too. And add the required code to the top and bottom of the page using Pre-/Appending. But that only work for files with a .php extension.
    So is there any other way to add the code to every page, or is there an error in my PHP config that keeps it from appending to .htm files?

    I also noticed my previous reply wasn't very polite, sorry about that.

  6. #6
    look up mod_layout
    * Rusko Enterprises LLC - Upgrade to 100% uptime today!
    * Premium NYC collocation and custom dedicated servers
    call 1-877-MY-RUSKO or paul [at] rusko.us

    dedicated servers, collocation, load balanced and high availability clusters

  7. #7
    Join Date
    Oct 2002
    Posts
    58
    Tnx, that's exactly what I need. Unfortunately I'm on win32, so I can't compile mods that easily.
    But I found something that get the job done (partially):

    rewrite.php:
    PHP Code:
    <?php
    if (isset($_GET['page'])){
        
    $page $_GET['page'];
        
    //Check if the page exists and if the user isn't trying to go a dir up
        
    if (!file_exists($page) OR ereg("/.."$page)){ $page "default.htm"; }; 
    }else{
        if (
    file_exists("index.htm")){
            
    $page "index.htm";
        }elseif (
    file_exists("index.html")){
            
    $page "index.html";
        }else{
            
    $page "default.htm";
        };
    };


        function 
    callback($buffer) {
    //do your rewrite stuff
    $buffer eregi_replace("</body>"""$buffer);
    $buffer eregi_replace("</html>"""$buffer);
    return (
    $buffer);
        }
        
        
    ob_start("callback");
        
        include 
    "$DOCUMENT_ROOT/user/$page";
        
        
    ob_end_flush();

    //include a footer or disclaimer or something

    ?>


    </body>
    </html>
    .htaccess:
    Code:
    RewriteEngine on
    RewriteRule ^(.*).html$ rewrite.php?page=$1.html
    RewriteRule ^(.*).htm$ rewrite.php?page=$1.htm
    
    Directoryindex rewrite.php
    This doesn't work for subdirectories...


    Thanks for your help guys

Posting Permissions

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