Dynadot

[TUTORIAL] Forced ads for resellers

Spaceship
Watch
Ok, well I finally found it... Forced ads with .htaccess file! Right now this works for .html & .htm extensions, but I'm working on getting it to .php as well, I will update as I figure that one out, it's a little more difficult for obvious reasons. (Quotes, syntax, etc. And above all, it parses through a PHP script)

MUST have the php_read function enabled! (Most webservers have this on by default)

YES! This is a free alternative to all the software out there

First, go into your cPanel account. (Reseller)

Now, not in WHM, but cPanel go into File Manager.

Find your cPanel skeleton directory.

In here... What we will do...

First create a new folder... Name it.. header...

In this folder create 3 text documents...

1 text document named: header.php
1 text document named: header.html
1 text document named: footer.html

In header.php insert the following code:
PHP:
<?php
$header = "header.html";
$footer = "footer.html";
$file = $_SERVER['SCRIPT_FILENAME'];

readfile($header);
readfile($file);
readfile($footer);
?>

In header.html insert your ad code you wish to be set in the header.

In footer.html insert your ad code you wish to be set in the footer.


Now go back up one directory... Edit your .htaccess file..

Add this somewhere:

Code:
AddHandler headered .html # Enable adds on HTML pages
AddHandler headered .htm # Enable adds on HTM pages
AddHandler headered .php # Enable adds on PHP pages
Action headered /header/header.php

==============================================
Ok, now that we have that finished, I have an iFrame code you can use!

Now, let's begin..

Open backup your header.html file.. Change it to this: (Footer will not be iFrame unless you do so doing the same process)
HTML:
<HTML>
<center><iframe src="http://yoursite.com/header/iframesrc.adsource" scrolling="no" width="48.2%" height="12%"></iframe></center>
</HTML>
<html>

Now, we need to create a new file... Create a new text document and name it: iframesrc.adsource (Be sure to place it in the "header" directory)

Insert you're ad code into that page...


But wait... Perplexed? That is correct, we still need to make the .adsource extension a valid one! So here is what we'll do.

Get out of the skeleton directory and go into the reseller account's /public_html folder. Open the .htaccess file..

In the .htaccess file add this somewhere:
Code:
AddHandler server-parsed adsource
AddType text/html adsource

Do this just in the reseller's .htaccess or wherever the ad code is being read from... This way the .adsource extension is not available for all users.

==============================================
At the current time it is not very secure for the user will be able to edit it, but I am working on it.. This is the basic concept and as I make changes I will create a changelog at the bottom of this post! Now creating an account will automatically ad your adcode to the site! Just make sure if needed you ad that domain to your publisher account with the ad company :)

-RageD
 
Last edited:
1
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Great work!

Got to try that out.

Thanks...
 
0
•••
Looking to 'force ads' I found something called mod_layout and, better (I believe, but I'm not a real webmaster) http://www.ihostdev.com/ipanel.html . It looks good but I don't have a dedicated server to install it.

Does anybody has install it on a VPS?

I'm looking for a good provider of VPS where I am sure it can be installed.

Any suggestion?

Thanks.
 
0
•••
There are indeed costly programs such as iPanel, but this is a completely free alternative as mentioned above.

-RageD
 
0
•••
I agree

In fact, it looks very creative.

By the way, did you find the way to make the appear on PHP scripts?

My previous Reply was only looking if someone else found another way to do that, inclusive, under payment. My problem is that I don't have the money for a dedicated server (and, monthly fees :'( ) but I can try to pay once for a script (that can be installed on a cheaper shared hosting service).

Sorry for any inconvenience i've caused.
 
0
•••
i think this is a nice little way of garanteeing that you have ads on your hosting accounts :)

nice one

Joe
 
0
•••
there is another way to do this with just using .htaccess and just using the .htaccess file itself forget how to do it right now, if I find my free hosting script ill pull it out of it.
 
0
•••
i did everything that you said properly.. (i have not used iframes right now.. just the basic one)

but i am getting this error
Fatal error: Call to undefined function: () in /home/XXXXX/public_html/header.php on line 6

please tell me whats wrong.. also how to do it directly with .htaccess?
 
0
•••
You used this code exactly in your header.php file?

PHP:
<?php
$header = "header.html";
$footer = "footer.html";

$file = $_SERVER["PATH_TRANSLATED"];
$readfile($header);
$readfile($file);
$readfile($footer);
?>

It must be like that and you must have your header.html file in the same directory so it can be read by this file.

-RageD
 
0
•••
well i dont think that there is any problem with the header.html or footer.html

i did one trick to check that out. i removd all the header and footer entries.. so that now the code stands as

Code:
<?php 

$file = $_SERVER["PATH_TRANSLATED"];  
$readfile($file); 
 
?>

here is the error log that i am getting

Code:
[27-Oct-2006 01:57:47] PHP Fatal error:  Function name must be a string in /home/gaurav/public_html/header/header.php on line 4
[27-Oct-2006 01:58:07] PHP Fatal error:  Function name must be a string in /home/gaurav/public_html/header/header.php on line 4

can u please tell me if i have to change somthing with PATH_TRANSLATED or anything according to my server or location?

i think it is some problem with string functions or something as the error log says?
 
Last edited:
0
•••
You can try to do this manually:

For $file = $_SERVER['PATH_TRANSLATED']; try this:

PHP:
$file = "/home/YOUR_USERNAME/public_html/SCRIPT_DIRECTORY/header.php";

-RageD
 
0
•••
did that but it is still not working :(.. is it possible that my server admins may have blocked this kind of a function ???

and one more thing, i will give u one free cpanel hosting account with 100mb space+ 1gb bandwidth to experiment..
 
0
•••
very nice!
not sure i really want to use it though
but for people who do
this is awesome

Joe
 
0
•••
0
•••
this does not work, tried every way said above?
still get this error

Fatal error: Call to undefined function: () in /home/cbmania/public_html/header/header.php on line 6
 
0
•••
Oh I would have never thought of this! Thank you very much, Nice tutorial!
 
0
•••
prowebhoster said:
this does not work, tried every way said above?
still get this error

Fatal error: Call to undefined function: () in /home/cbmania/public_html/header/header.php on line 6

Ok, is your header.php file named correctly and in the /public_html/header directory? If so, did you check the correction above making $file direct straight to that file?

-RageD
 
0
•••
Anyone can just delete the folder and edit their htaccess, even the people with no knowledge about this type of stuff.
 
0
•••
ok i got to know.. this was a problem with my server... i enquired ..something like "php read file" function must be enabled to successfully implement this technique... :)
 
0
•••
Normally this is already on, but I'll make sure I put it up there so people don't have this problem again! :)

-RageD
 
0
•••
hey raged, have you found any complete solution which puts headers for php files as well??

thanks a lot
 
0
•••
Actually I have.. This seems to work on PHP 4.x and 5.x. I will update the original post but instead of:

PHP:
$_SERVER["PATH_TRANSLATED"]

it seems rather that:
PHP:
$_SERVER['SCRIPT_FILENAME']

is a better alternative!

Cheers,
-RageD
 
1
•••
yippie finally a php version as well... desperately waiting for that one dude :)
 
0
•••
champ_rock said:
yippie finally a php version as well... desperately waiting for that one dude :)
Just like me.

Thanks for sharing!
 
0
•••
Just felt I'd revive this one for anyone who is looking for such a solution again! :)

Also, I have not tested this but here is an idea. If you would like to keep the "header" directory untouchable by the user and have root access (many don't but that's alright. Maybe it would work with just SSH access on a reseller) try this:

cd /home/USER/public_html
chown root headers/
chown root headers/*

Again, I have not tried this. You may want to test that apache still allows the file to be executed in the browser but it should. After CHOWN'ing to root or another user (resellers try with chown YOURUSER) the user will be unable to edit the file.

-RageD
 
Last edited:
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back