Jump to content

Global.asa equivelent


RyanSmith345

Recommended Posts

Hello PHP communtiy.

I know that I have found the answer to this before, but I need to figure out how to make a PHP call on every webserver request.  I can do this in ASP/ASP.NET with the Begin_Request method in the Global.asa

How can I accomplish this in PHP.

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/22428-globalasa-equivelent/
Share on other sites

For example, in ASP.NET, you have a file called Global.asax.  There are several methods in this file that get called on certain actions.

Application_Start
Session_Start

and the big one that I'm interested in is

Begin_Request - this gets fired everytime a request comes in, well at least a reqeust that will be processed with the ASP.NET worker process.

What I'm looking to do is build a stats tracer.  With the method above, I can assign PDF's and other files that don't execute any server side code to be processed with ASP.NET and this event will get fired on every web request.  That way I can track statistics for every file, not just PHP page requests.
Link to comment
https://forums.phpfreaks.com/topic/22428-globalasa-equivelent/#findComment-100967
Share on other sites

I am not sure but I don't think that php has a function for this.. Maybe you should use javascript (ajax) to send results to a back end php file for processing. You could have an onClick event, which would call the processing function, for each file or page. Of course this would not work if the client directly accesses the file..

Maybe someone else would be of more use on this..

Good Luck,
Tom
Link to comment
https://forums.phpfreaks.com/topic/22428-globalasa-equivelent/#findComment-101091
Share on other sites

Funny, I have had that exact suggestion from WebTrends before.

That's the issue is I really need to be able to track on every web request, and JavaScript is a poor solution to statistics gathering as there are just too many people out there with JS diabled, Spiders, Mobile Devices, the list goes on and on.

I'm starting to think the way to go is to create an ISAPI filter for IIS and an Apache Module that you can simply plugin.  Unfortunally, I don't know how to code either of those off the top of my head so that could be some serious research time.

Regardless, I would still like to know if this is possible with PHP and hear any other possible solutions that people might have.

Thanks for your suggestion.
Link to comment
https://forums.phpfreaks.com/topic/22428-globalasa-equivelent/#findComment-101111
Share on other sites

I think I actually have the source code for Webalizer, but I HATE C++.  If I have to write it in C++, I'll probably not do it at all.

I'm actually very excited for the new IIS 7 in vista to come out.  It looks like it is going to be extreamly easy to code up extensions.  Too bad I'll still be supporting all of these legacy 2000 boxes we have around.
Link to comment
https://forums.phpfreaks.com/topic/22428-globalasa-equivelent/#findComment-101122
Share on other sites

Just use the php.ini settings! (per_dir via .htaccess or globally via php.ini), acts just like a include file, it has global scope of all SUPER GLOBALS before any script it executed!

auto_prepend_file =

auto_append_file =

info [url=http://us2.php.net/ini.core]here[/url]

me!
Link to comment
https://forums.phpfreaks.com/topic/22428-globalasa-equivelent/#findComment-101124
Share on other sites

This is working the way I want it, however I have run into another issue.  I want to append this code to PDF requests as well so I can track the so I added the following to the httpd.config file:

AddType application/x-httpd-php .pdf

This works as expected, however PHP chokes when it tries to process the PDF file.

Is there a way to tell PHP to stop processing the file after a certain point and just output the rest like normal HTML?

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/22428-globalasa-equivelent/#findComment-101145
Share on other sites

You have to process the document your self, because a PDF file is not a PHP file, so all you do is...

in the global prepend...

1. do your statistics process as you normally would
2. get the SUPER GLOBAL => $_SERVER['SCRIPT_NAME']
3. substr() it to get the script extension (ie: pdf, php)!
4. if it is a (pdf), serve it then exit!
5. if it's not a pdf, let PHP continue!

simple working example!

[code=php:0]<?

// do your tracking (statistics) process here

/* then for pdf(s) */

$script = basename ( $_SERVER['SCRIPT_NAME'] );

$type = strtolower ( substr ( $script , ( strrpos ( $script, '.' ) + 1 ) ) );

if ( $type == 'pdf' )
{
header ( 'Cache-control: max-age=31536000' );
header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
header ( 'Content-Length: ' . filesize ( '.' . $_SERVER['SCRIPT_NAME'] ) );
header ( 'Content-Disposition: filename="' . $script . '"' );
header ( 'Content-Type: application/pdf; name="' . $script . '"' );
readfile ( '.' . $_SERVER['SCRIPT_NAME'] );
exit ();
}

// let the script call continue if it not a pdf!

?>[/code]

nice and simple...

updated to add strtolower() for [b]$type[/b]

me!
Link to comment
https://forums.phpfreaks.com/topic/22428-globalasa-equivelent/#findComment-101162
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.