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

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

Execute PHP script automatically for each page request

Post 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
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post 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

Code: Select all

myfunction();
to

Code: Select all

myfunction($_SERVER['PHP_SELF');
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
pooh14
Forum Newbie
Posts: 23
Joined: Tue Apr 04, 2006 12:20 am

Post 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.
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post 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
jito
Forum Commoner
Posts: 85
Joined: Sat Mar 25, 2006 4:32 am
Location: india

Post 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.
pooh14
Forum Newbie
Posts: 23
Joined: Tue Apr 04, 2006 12:20 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
pooh14
Forum Newbie
Posts: 23
Joined: Tue Apr 04, 2006 12:20 am

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
pooh14
Forum Newbie
Posts: 23
Joined: Tue Apr 04, 2006 12:20 am

Post 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)
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post by rubberjohn »

can i just ask what does the AuthenticationModule.php does?
pooh14
Forum Newbie
Posts: 23
Joined: Tue Apr 04, 2006 12:20 am

Post 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.
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post 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

Code: Select all

$_REQUEST['page']
will extract 'football.html'

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

Post 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
Post Reply