Page 1 of 2
Execute PHP script automatically for each page request
Posted: Sun Apr 09, 2006 2:47 am
by pooh14
Hi Guys,
I have a problem and really need help asap.
I am using Apache web server.
I would like to know how to make the apache execute my PHP script automatically for every page request.
at the same time, it has to pass the requested page filename to my PHP Script.
I hope somebody can really help me. I am newbie to this kind of stuff.
Thank you
Posted: Sun Apr 09, 2006 7:00 am
by rubberjohn
im not really sure I understand what you mean...
if it is a funtion you want to run everytime a page loads then you could put the function in a separate file, include the file in every page you want it to run along with a function call:
Code: Select all
include "myfunctionfile.php";
myfunction();
if by
it has to pass the requested page filename to my PHP Script.
you mean the current page or the page that has called the function change
to
the argument inside the () will pass the current page to the function.
by no means am i an expert but that is how i would do it
rj
Posted: Sun Apr 09, 2006 7:13 am
by pooh14
hi thanks for your reply.
actually for every page request apache receives, whether it is a html page or php page, before displaying the page, i want it to execute another php script. I want the requested filename to be sent to the script to
In that script I am receiving filename using S_GET.
Once the script is executed, then it goes back to the requested page.
Posted: Sun Apr 09, 2006 8:03 am
by rubberjohn
im not sure if there is a way to get apache to execute a script for every page request.
what about using an intermediate page - direct all of the links to the intermediate page, carry out the necassary processing, and then redirect to the appropriate page...
some more details would be helpful
Posted: Sun Apr 09, 2006 8:13 am
by jito
hi,
will u pls explain it a bit with an example? i am not sure what's ur problem.
Code: Select all
header("Location: <somelocation>"); //redirect browser
is that what u want? if so check the manual.
Posted: Sun Apr 09, 2006 9:33 am
by pooh14
ok assuming in my html page now, i am calling Football.html.
before apache displays the requested page, I want it to execute my php script which i have written (AuthenticationModule.php)
I also want it to pass the requested page filename (in this case, Football.html) to my script
In my script, I am accepting the filename parameter using GET. However i am willing to change the way i accept the parameter, if there is another possible way.
So i want this to happen for every page request. Is it possible???
Thanks in advance...Help really needed
Posted: Sun Apr 09, 2006 9:36 am
by feyd
It is possible, but the requested file must be processed by php for it to work.
Have a look at the
auto_prepend_file directive.
Posted: Sun Apr 09, 2006 10:01 am
by pooh14
hi,
the thing is i want it to work for html files too.
besides if i am using auto_prepand, how do i send the requested page filename. i know u can use $_SERVER[PHP_SELF] to get the filename of the current script, but how do i join that together with my auto_prepand?
like this ?? (it doesnt work:p)
auto_prepand_file ="c:/Apache/include/AuthenticationModule.php?filename+($_SERVER["PHP_SELF"))"
I am accepting the parameter using GET in Authenticationmodule
Posted: Sun Apr 09, 2006 10:05 am
by John Cartwright
look in your httpd.conf file under AddType or AddHandler I believe, which lists the extensions of files which will load the PHP engine. Simply include .html

Posted: Sun Apr 09, 2006 10:09 am
by feyd
pooh14 wrote:besides if i am using auto_prepand, how do i send the requested page filename. i know u can use $_SERVER[PHP_SELF] to get the filename of the current script, but how do i join that together with my auto_prepand?
You cannot send get request information to the prepend script through the reference to it. Why? Because the prepended file is apart of the same request. The data is available in $_SERVER et al already.
Posted: Sun Apr 09, 2006 10:38 am
by pooh14
hi feyd,
i am really sorry, but I have no idea on how to do it at all.
I know this really sounds dumb.
Can you give me a more detail explain?
where do i call the script? how do i pass the $_Server[PHP_SELF] variable to it?
How do i accept in my script (at the moment i am using GET to accept parameter)
Posted: Sun Apr 09, 2006 11:24 am
by rubberjohn
can i just ask what does the AuthenticationModule.php does?
Posted: Sun Apr 09, 2006 11:31 am
by pooh14
hi,
ok let me explain more. I am a student and this is for my project (which is why i am rushing to meet the deadline)
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.
so i did a module, AuthenticationModule which will do all this stuff and i successfully did it.
but now my problem part is how am i going to call it for each page request without much changes made to the original page.
so i was hoping if i can just change one main configuration file. thus all pages before being displayed it is verified.
Posted: Sun Apr 09, 2006 11:47 am
by rubberjohn
can you link to the authmodule and send the page in the URL
say a link like this is on your home page
Code: Select all
<a href="AuthenticationModule.php?page=football.html">FOOTBALL</a>
and then in the authmodule
will extract 'football.html'
rj
Posted: Sun Apr 09, 2006 11:49 am
by pooh14
Hi john
thanks. ya that I can do. but the thing is, my project focuses on authentication module.
my main aim is to provide a system which can verify integrity of page before displaying it.
however, i would like to make sure, the already design web pages, need not be altered much inorder for my module to be incorporated as this would reflect bad design.
so i was thinking if there is a way i just change one main configuration file, n not all the links in every page