Web Hosting Talk







View Full Version : PHP Auto Pre-/Append


Thanatos
11-15-2002, 03:27 PM
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:
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?"

phpa
11-16-2002, 06:21 AM
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?

Thanatos
11-16-2002, 12:38 PM
No, I won't add any banners or alike to his site.

Does anybody have a real suggestion to help me out?

phpa
11-16-2002, 07:49 PM
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.

Thanatos
11-17-2002, 05:23 AM
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.

rusko
11-17-2002, 07:37 AM
look up mod_layout

Thanatos
11-18-2002, 04:01 PM
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
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:
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