Jump to content


Photo

Execute PHP script automatically for each page request


  • Please log in to reply
13 replies to this topic

#1 laavanya14

laavanya14
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 09 April 2006 - 08:11 AM

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

#2 theteenager

theteenager
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 April 2006 - 08:30 AM

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:

AddType application/x-httpd-php .htm .html

The requested filename will be in the variable $_SERVER["PHP_SELF"]
[a href="http://www.hanburger.net" target="_blank"]Hanburger[/a]. No, not hamburger, but I could go for one right about now...

#3 laavanya14

laavanya14
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 09 April 2006 - 11:28 AM

[!--quoteo(post=362945:date=Apr 9 2006, 03:30 AM:name=Honzoo)--][div class=\'quotetop\']QUOTE(Honzoo @ Apr 9 2006, 03:30 AM) View Post[/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:

AddType application/x-httpd-php .htm .html

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

#4 SomeGuy1337

SomeGuy1337
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 09 April 2006 - 01:36 PM

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

#5 laavanya14

laavanya14
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 09 April 2006 - 02:27 PM

[!--quoteo(post=362976:date=Apr 9 2006, 08:36 AM:name=SomeGuy1337)--][div class=\'quotetop\']QUOTE(SomeGuy1337 @ Apr 9 2006, 08:36 AM) View Post[/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??



#6 SomeGuy1337

SomeGuy1337
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 09 April 2006 - 03:40 PM

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

#7 laavanya14

laavanya14
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 09 April 2006 - 03:54 PM

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
a href='authenticationmodule.php?file=football.html'

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

#8 SomeGuy1337

SomeGuy1337
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 09 April 2006 - 04:37 PM

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.

#9 laavanya14

laavanya14
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 09 April 2006 - 06:57 PM

[!--quoteo(post=363031:date=Apr 9 2006, 11:37 AM:name=SomeGuy1337)--][div class=\'quotetop\']QUOTE(SomeGuy1337 @ Apr 9 2006, 11:37 AM) View Post[/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


#10 SomeGuy1337

SomeGuy1337
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 10 April 2006 - 06:32 AM

if you preappend auto file then it will contain football.html

alternativly if you authmodule fetches football.html then shouldnt u have that value?
like authmodule.php?get=football.html

#11 laavanya14

laavanya14
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 11 April 2006 - 04:32 PM

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
<a href="page3.html">Page3</a>
, then the solution works fine.

however, if in page1, instead of link i have
include('page3');
then in my AuthenticationModule,
$filename=$_SERVER('PHP_SELF');
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?

#12 laavanya14

laavanya14
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 12 April 2006 - 04:21 AM

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
<?php
          include('page3.php');
        ?>

thus if i have auto_prepend page2.php, it does not get executed before calling of page3. Can I solve this problem???

#13 SomeGuy1337

SomeGuy1337
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 12 April 2006 - 09:46 AM

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

#14 laavanya14

laavanya14
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 12 April 2006 - 12:58 PM

Hi

Ya,thats what i am doing normal.
For every requested page, I parse to check if there is include or require statements.....

thanks aloooot anyway




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users