Jump to content

Global.asa equivelent


RyanSmith345

Recommended Posts

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