Execute PHP script automatically for each page request

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

pooh14 wrote:hi,

my aim of the project is to verify the integrity of a webpage and if any aunthorized changes has been made to it, it would restore to the original content. besides all pages are encrypted and stored. thus for each request it needs to be decrypted.
Where are they stored? How are they retrieved? Imho it seems less obtrusive if you plugin that verification stuff at retrieval time... (Thinking about hashes of the encrypted or unencrypted content here).
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post by rubberjohn »

so basically you want to set a high level condition on the server that directs all page requests through the authmodule without making any changes to the existing html??

i may be corrected but i dont think this can be done

did you try out feyd's suggestion??
pooh14
Forum Newbie
Posts: 23
Joined: Tue Apr 04, 2006 12:20 am

Post by pooh14 »

hi guys,

but prepending the file and using $_SERVER in my script, i manage to solve the problem partially.

however, if i m going to call a particular page using include('pooh.php') instead of the normal hyperlink method, the $_SERVER does not hold the requested page, instead the page which contains the include statement.

how do i solve the problem?

thanks alot
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

__FILE__
pooh14
Forum Newbie
Posts: 23
Joined: Tue Apr 04, 2006 12:20 am

Post by pooh14 »

Hi Feyd,

Thanks.

echo basename(__FILE__,".php") just prints the filename of the current file, not the module i called for.

assuming i have 3 scripts, page1, page2, page3


so in page1, i have include(page3)

assuming i have auto_prepand page2

in page2, i print out basename(__FILE__), i get page2.

what i would like it to find out is the requested page by page1, which is page3.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

pooh14 wrote: so in page1, i have include(page3)
assuming i have auto_prepand page2
In this case the code in page2 is executed before the code in page1... Thus at that moment you don't have a crystal ball and can't know what's going to happen in page1 ;)

Well, the easiest work-around to me seems that you define a function on page1 that returns the page you'll include...

Code: Select all

function getPage() {
 // do whatever
 return 'page3';
}
This way you know what's going to be included in page1.
pooh14
Forum Newbie
Posts: 23
Joined: Tue Apr 04, 2006 12:20 am

Post by pooh14 »

Hi,

Thank timvw. but i think you dont really understand my problem.

as i said earlier, my AuthenticationModue(auto-prepended file) is an extra module i did to check integrity of the pages...

this is my univeristy project.

however my main aim is when i merge this AuthenticationModule with existing web pages, I would not much changes done to the existing website (good design purpose). thus i would just like one main configuration change.

so all i need to know is the requested filename in my authenticationmodule, at the momend i dun have problem with normal href links....however i have problem when the file is requested using include statements.

thank you
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

The easiest way to do this would be to configure Apache (httpd.conf) to include a header on every page request, which could be the .php file. As long as that file isn't sending out any data all the pages will still look the same and the php script will be executed.
pooh14
Forum Newbie
Posts: 23
Joined: Tue Apr 04, 2006 12:20 am

Post by pooh14 »

Hi agtlewis,

Thanks for reply.

I am sorry, but I really have no idea what you were trying to explain :oops:

Hope you can explain in more detail and sorry for troubling you
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Nevermind, what I am talking about only works for directory listings.
HeaderName names the file which, if it exists in the directory, is prepended to the start of server generated directory listings. Like ReadmeName, the server tries to include it as an HTML document if possible or in plain text if not
pooh14
Forum Newbie
Posts: 23
Joined: Tue Apr 04, 2006 12:20 am

Post by pooh14 »

guys,

I just realize, include is not really a request, thus auto_prepend wont really work for include statement

include is more like pasting the code in the same file right?????
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I find that you're doing very little research yourself for a university project. (http://www.php.net/include)
Post Reply