Setup For .html/.htm Files Without A Footer File

Discussion in 'Co-op Advertising Network' started by digitalpoint, Dec 1, 2004.

  1. #1
    Here's a quick little setup if you have a site where the server supports mod_rewrite and PHP, but all your files are .htm or .html...

    All these files would go in the root folder of your site:

    .htaccess
    <IfModule mod_rewrite.c>
    	RewriteEngine On
    	RewriteBase /
    	RewriteCond %{REQUEST_FILENAME} ^(.*).htm [NC,OR]
    	RewriteCond %{REQUEST_FILENAME} ^(.*).html [NC]
    	RewriteRule ^(.*)       /passthru.php?file=$1
    </IfModule>
    Code (markup):
    passthru.php
    <?php
    	
    	if (!function_exists('file_get_contents')) {
    		function file_get_contents($url) {
    			$handle = fopen($url, 'r');
    			$string = fread($handle, 4096000);
    			fclose($handle);
    			return $string;
    		}
    	}
    	
    	include ('ad_network.php');
    	echo preg_replace ("/<\/body>/i", $ad_network . '</body>', file_get_contents(str_replace ('../', '', $_REQUEST['file'])));
    
    ?>
    PHP:
    Drop the normal ad_network.php and empty ad_network_ads.txt file into the folder as well.

    What it will do is read any .htm or .html file, and insert the ad before the </body> tag. You can change it up to adjust formatting or for multiple ads, but it should be a start for those that need it.
     
    digitalpoint, Dec 1, 2004 IP
  2. rustybrick

    rustybrick User ID 3

    Messages:
    385
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    158
    #2
    Isnt he just great?
     
    rustybrick, Dec 1, 2004 IP
  3. chachi

    chachi The other Jason

    Messages:
    1,600
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    0
    #3
    wonder if the guy ever sleeps
     
    chachi, Dec 1, 2004 IP
  4. Stretch

    Stretch Peon

    Messages:
    33
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks Shawn

    What's the advantage of using passthru.php instead of having:

    AddType application/x-httpd-php .php .htm .html

    in your .htacess and including the code as per usual?
     
    Stretch, Dec 1, 2004 IP
  5. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #5
    The only real advantage is you don't have to add the PHP code to all the files.
     
    digitalpoint, Dec 1, 2004 IP
    browntwn likes this.
  6. Stretch

    Stretch Peon

    Messages:
    33
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Oh, I get it now. Very cool. Thanks again.
     
    Stretch, Dec 1, 2004 IP
  7. seohome

    seohome Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi Shawn,

    Two problems:

    How do I add it to the main page? For some reason (I'm guessing because it doesn't end in .htm) the ads don't appear in there.

    How do I add multiple ads? I can only add one...

    Thanks
     
    seohome, Dec 1, 2004 IP
  8. schlottke

    schlottke Peon

    Messages:
    2,185
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #8
    seohome, you add that code into the .htaccess file.
     
    schlottke, Dec 1, 2004 IP
  9. seohome

    seohome Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    .... which code?

    Sorry, not an expert programmer
     
    seohome, Dec 1, 2004 IP
  10. schlottke

    schlottke Peon

    Messages:
    2,185
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #10
    The top code, the one below .htaccess in bold.
     
    schlottke, Dec 2, 2004 IP
  11. zamolxes

    zamolxes Peon

    Messages:
    176
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I've tried adding the code to the .htaccess file but that causes an internal server configuration error. I tried it on 2 servers - no success.
     
    zamolxes, Dec 2, 2004 IP
  12. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #12
    You server may not allow mod_rewrites... if you check your error log, you will know for sure.
     
    digitalpoint, Dec 2, 2004 IP
  13. seohome

    seohome Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I added that code. I mean, the script IS working for me. It just doesn't appear in the index...

    Also, I don't know how to add multiple ads with this system (the code is too messy for me to handle it :confused: )...

    Thanks again for the help
     
    seohome, Dec 2, 2004 IP
  14. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #14
    Is your index a .html or .htm file?

    For two ads (as an example) you could add:
     . ' - ' . $ad_network[1]
    PHP:
    right after the $ad_network[0] variable. That will put a dash between them.
     
    digitalpoint, Dec 2, 2004 IP
  15. seohome

    seohome Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    My index is a .htm and so are all my other pages but the ads don't appear in the index :confused:

    I tried to add that code to have multiple ads (exactly the same) but I didn't succeed. I guess it is because I have to write an include for each ad_network... but where do I add it?

    Thanks Shawn
     
    seohome, Dec 2, 2004 IP
  16. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #16
    What's your site URL?

    You don't need multiple includes if you have the latest ad_network.php file (from yesterday or today).
     
    digitalpoint, Dec 2, 2004 IP
  17. seohome

    seohome Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    My URL is http://www.poems-and-poetry.com

    By the way, I've added the multiple ads thanks to the new ad_network.php :)

    Edit: I made the code to replace "SEO Firm: SEOHome" by the way.
     
    seohome, Dec 2, 2004 IP
  18. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #18
    Not sure to be honest... They are there if you specifically specify index.htm I also tested it on this end, without the filename being specifically specified and it's working for me. So the only thing I can think of is maybe Apache isn't seeing the actual filename somehow with the %{REQUEST_FILENAME} variable.
     
    digitalpoint, Dec 2, 2004 IP
  19. seohome

    seohome Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    Yeah... I tried to add some more conditions to the .htaccess regarding the domain but couldn't do it.

    The only way I got the ads to appear is by placing
    AddType application/x-httpd-php .php .htm .html
    PHP:
    in the .htaccess above
    <IfModule mod_rewrite.c>
    	RewriteEngine On
    	RewriteBase /
    	RewriteCond %{REQUEST_FILENAME} ^(.*).htm [NC,OR]
    	RewriteCond %{REQUEST_FILENAME} ^(.*).html [NC]
    	RewriteRule ^(.*)       /passthru.php?file=$1
    </IfModule>
    PHP:
    and the other code directly in the index. However, when I did this, the ads stopped appearing in the internal pages :rolleyes:
     
    seohome, Dec 2, 2004 IP
  20. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #20
    You could do it with the rewrite, then change your index.htm to index.php I suppose... unless you are linking specifically to index.htm somewhere.
     
    digitalpoint, Dec 2, 2004 IP