Jump to content

Execute PHP script automatically for each page request


laavanya14

Recommended Posts

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 (whether php or html pages).

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
Link to comment
Share on other sites

Just have more types assigned to PHP. For example, if you want html and html files to be parsed by PHP, just add the following to httpd.conf:

[code]AddType application/x-httpd-php .htm .html[/code]

The requested filename will be in the variable $_SERVER["PHP_SELF"]
Link to comment
Share on other sites

[!--quoteo(post=362945:date=Apr 9 2006, 03:30 AM:name=Honzoo)--][div class=\'quotetop\']QUOTE(Honzoo @ Apr 9 2006, 03:30 AM) [snapback]362945[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Just have more types assigned to PHP. For example, if you want html and html files to be parsed by PHP, just add the following to httpd.conf:

[code]AddType application/x-httpd-php .htm .html[/code]

The requested filename will be in the variable $_SERVER["PHP_SELF"]
[/quote]


Hi, but how do i automatically call another script??
and how do i pass the requested filename to it, even if it is html file..

sorry if it a silly question but desperate for help :p

thanks alooooooooot
Link to comment
Share on other sites

[!--quoteo(post=362976:date=Apr 9 2006, 08:36 AM:name=SomeGuy1337)--][div class=\'quotetop\']QUOTE(SomeGuy1337 @ Apr 9 2006, 08:36 AM) [snapback]362976[/snapback][/div][div class=\'quotemain\'][!--quotec--]
auto_prepend_file
auto_append_file

these are in the php.ini config file

and you can use basename($_SERVER["PHP_SELF"]) to get just the filename and strip the direcotry
[/quote]


hey using auto_prepand_file, would it work if my requested page is html????

my script name is AuthenticationModule, n in my script i am accepted the requested page filename using GET method. if there is any other way of accepting, i dun mind changing.

auto_prepand_file ="c:/Apache/include/AuthenticationModule.php?filename+($_SERVER["PHP_SELF"))



is that how i do it??

Link to comment
Share on other sites

the php.ini is static, its jsut to setup php variables u cant exciute php code in it

im not sure entirely wat u want to do?

as teh afore mentoined by honzoo:
AddType application/x-httpd-php .htm .html

this will make any html page be sent thru the php interpreter

auto_prepend and append file will mean any file sent thru the php interprter will have those files added in before and afterwards as if you had include "somefile.php" at the top and bottom of every php file

basename($_SERVER["PHP_SELF"]) will tell you the current filename in use for example if you had
[a href=\"http://localhost/dir/myfile.php\" target=\"_blank\"]http://localhost/dir/myfile.php[/a]
it would be "myfile.php" as the variable

but i am unsure ezactly wat you are tyring to do could you be more specific about ezactly what you want to achive
Link to comment
Share on other sites

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 needed too. Once processed, the requested page is displayed.

Just to let you know what AuthenticationModule is doing, it verifies the intergrity of the page. Once verified, the normal process goes, meaning the page is displayed. This is for my university project. I am suppose to do an AuthenticationModule which verifies webpages before displaying it. So I have already done the module but now I am not sure how to link it for every request

The easy but not so good way would be
[code]a href='authenticationmodule.php?file=football.html'[/code]

but in this case, i need to change each and every link which is not good in the design part of my system.
i just would like to make it one main configuration change and it does for every link.

Thanks in advance...Help really needed
Link to comment
Share on other sites

ok if you preappend Auth.php (or the filename doenst matter.)

browser requests
[a href=\"http://site.com/mypage.html?var=value\" target=\"_blank\"]http://site.com/mypage.html?var=value[/a]

you site will run auth.php
from auth.php:
basename($_SERVER["PHP_SELF"]) = mypage.html
$_GET['var'] = 'value'

at this point i hvae to say i have not peronsaly used the preappend and append php.ini settings.
but to my knwoladge they shud perform just as if you had used include "preappend.php" inside mypage.html

setup your authmodule to echo those variables and set it as the preappend file
if all goes well when you access football.html?var=value it should show you those values

try setting this up it shud solve your problem.
Link to comment
Share on other sites

[!--quoteo(post=363031:date=Apr 9 2006, 11:37 AM:name=SomeGuy1337)--][div class=\'quotetop\']QUOTE(SomeGuy1337 @ Apr 9 2006, 11:37 AM) [snapback]363031[/snapback][/div][div class=\'quotemain\'][!--quotec--]
ok if you preappend Auth.php (or the filename doenst matter.)

browser requests
[a href=\"http://site.com/mypage.html?var=value\" target=\"_blank\"]http://site.com/mypage.html?var=value[/a]

you site will run auth.php
from auth.php:
basename($_SERVER["PHP_SELF"]) = mypage.html
$_GET['var'] = 'value'

at this point i hvae to say i have not peronsaly used the preappend and append php.ini settings.
but to my knwoladge they shud perform just as if you had used include "preappend.php" inside mypage.html

setup your authmodule to echo those variables and set it as the preappend file
if all goes well when you access football.html?var=value it should show you those values

try setting this up it shud solve your problem.
[/quote]

hi, by doing basename($_SERVER["PHP_SELF"]) , it works only for normal link call, however if i doing include('football.html'), it doesnt show football.html instead the page calling include file
Link to comment
Share on other sites

Hi Guys,

I partially manage to solve my problem by using auto_prepend_file and $_SERVER('PHP_SELF');

if auto_prepend my AuthenticationModule and inside that script i write $filename=$_Server('PHP_SELF')) i can get my calling script.

assuming i have page1, AuthenticationModule, page3.
in page1, i have a link [code]<a href="page3.html">Page3</a>[/code], then the solution works fine.

however, if in page1, instead of link i have [code]include('page3'); [/code]
then in my AuthenticationModule, [code]$filename=$_SERVER('PHP_SELF'); [/code] then filename would be page1, instead of my requesting page, which is page3.

Is there anyway i can solve this problem for include file situations?
Link to comment
Share on other sites

Helo again.

I realize the if i include files, the php doesnt treat it like another file request. Meaning, the auto prepend file is not being executed before......

assuming in page1.php i have
[code]<?php
          include('page3.php');
        ?>
[/code]

thus if i have auto_prepend page2.php, it does not get executed before calling of page3. Can I solve this problem???
Link to comment
Share on other sites

all u need to do is get a system that handles this all for you.

every file that uses this system will have
require "mysystem.php"
oro something like that

this script can get the PHP_SELF variable for calling page, and it can then assess which extra files it needs to include, such as teh atuhmodule.php as standered.

this is also far more pratical, than using auto_prepend
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.