Page 1 of 2

Global.asa

Posted: Wed Jan 08, 2003 9:10 am
by vivek
Can any one tell me is there any thing like global.asa in php

Posted: Wed Jan 08, 2003 10:41 am
by maxim
what is Global.asa in your world?

Posted: Wed Jan 08, 2003 11:08 am
by BDKR
I suspect that an include file is what you're looking for. All of your class, function, whatever you want, can be put into an included file and called whenever you need.

Just make sure that you give it a .php extension. The early practice in the PHP community was to use .inc to denote included files. The problem is that the server doesn't parse these files if they are called individually representing something of a security risk. Most servers can be configured to parse .inc file as php, however, most people just change the name of the files to .php.

Cheers,
BDKR

Posted: Wed Jan 08, 2003 11:19 am
by DaiWelsh
global.asa is a special include file that is automatically 'included' before each ASP page is run (similar to application.cfm in Cold Fusion for anyone that knows it). Afaik there is no equivalent in php, you need to include a 'config' file into each page yourself, but then I am no expert.

HTH,

Dai

Posted: Wed Jan 08, 2003 11:41 am
by Elmseeker
Actually, if you have access to your php.ini you could write a file that includes all of the files, classes, functions, etc that you want included in every php page and then set that file in the php.ini auto_prepend_file section like:

auto_prepend_file = "/usr/local/lib/php/myclasses.php"

or what have you...

Posted: Wed Jan 08, 2003 3:26 pm
by DaiWelsh
Interesting. Is there any way to vary this for different sites and/or directories or would it apply across the board for PHP scripts on that server?

Posted: Wed Jan 08, 2003 3:32 pm
by Elmseeker
Well, done this way it's for all pages on the site. There is, I believe, a way to do it with certain directories only, using .htaccess or something, but I'm not sure how to do it. Maybe check the PHP web site and see if there is anything there about it...You COULD also, if it's available to you, use the CGI version of PHP which would make it so only YOUR files included it...

global.asa

Posted: Wed Jan 08, 2003 11:27 pm
by fractalvibes
I don't think you will find an equivalent of global.asa. Much of the usefullness of that is being able to have certain events occur upon Session Start, Session End, Application Start, and Application End. You might can roll your own, but I think session handling may yet be a little immature in
PHP. That sort of function is the only reason I have ever used global.asa....otherwise I declare session variables as I need them...and sparingly.

Included files I think just provide a subset of that functionality. If you could find a way to trap the PHP equivalent of session start and session end, you might can mimic the global.asa.

Perhaps if you explain what you are needing to accomplish, a better focus on the solution might be had.

Phil J.

Posted: Thu Jan 09, 2003 12:54 pm
by BDKR
I will agree with everyone that there is no equivalent to the Global.asa file in PHP, but the include file CAN be made to do whatever you want! So have at it. It seems like we spend too much time worrying about the lack of equivalents in various languages when we can just take what a language provides and create with it what we need.

As for this...
...I think session handling may yet be a little immature in PHP....
... in what way is PHP session handling immature?

Cheers,
BDKR

global.asa

Posted: Thu Jan 09, 2003 1:54 pm
by fractalvibes
I say that based upon my experience with PHP sessions. Perhaps it is actually a configuration issue - can't say since i don't host the site myself

1.) Don't know of any way to trap session.start, session.end, etc.
2.) Sometimes the session ID appears in the Address bar???
3.) Seems that session vars have to be declared in a special way to persist from page to page - declared as a global type of some sort...
4.) Seems that each page has to have a session_start command or previously declared session vars are unavailable in the page.
5.) Due to the above, sessions just do not operate as smoothly as in ASP, from my experiences. I am sure this will improve with each new release of PHP

Phil J.

Posted: Thu Jan 09, 2003 2:28 pm
by volka
I take the list as questions like "How can php ...." ;)
  1. e.g. http://www.php.net/manual/en/function.s ... andler.php or by using the auto-include you can check wether a session-var is set or not; if not it's a new session and the var. is set
  2. sessions can be handled in two ways, either by storing the sessionid in a cookies or by appending the sessionid to the url. Php offers both, see http://www.php.net/manual/en/ref.sessio ... -trans_sid
  3. anything that can be casted to a string can be stored in $_SESSION, e.g. $_SESSION['user']='me'; and will available at the next page within the same session
  4. session.auto_start=On in php.ini (and/or .htaccess?) and your sessions will start without calling session_register, but each request will use sessions ...even if unnecessary

Posted: Thu Jan 09, 2003 8:20 pm
by fractalvibes
Thanks for the info. I figured the session_start was a config issue.

Getting back around to the original issue - what was the initial poster wanting to do in a global.asa-like capacity?

No dissing of PHP intended by my remark - session functionality is a relatively new functionality of PHP and will no doubt keep improving.

Phil J.

Posted: Fri Jan 10, 2003 9:02 am
by BDKR
fractalvibes wrote:Thanks for the info. I figured the session_start was a config issue.

Getting back around to the original issue - what was the initial poster wanting to do in a global.asa-like capacity?

No dissing of PHP intended by my remark - session functionality is a relatively new functionality of PHP and will no doubt keep improving.

Phil J.
Hey Phil,

I myself didn't think you were dissin' PHP. I was just curious. Hope you didn't feel any heat from me as I wasn't intending as such.

Anyway, seeing as how Volka inserted $30.00 worth of fact there about sessions, I won't go on. Besides, I don't use PHP's session handling and prefer to store session data in a db with my own code. Much of this is a result of my feelings that if whatever site I create grows to a point of needing a server farm, then the session handling can make the leap without trouble.

Cheers,
BDKR

Posted: Fri Jan 10, 2003 9:13 am
by Elmseeker
BDKR wrote: Anyway, seeing as how Volka inserted $30.00 worth of fact there about sessions, I won't go on. Besides, I don't use PHP's session handling and prefer to store session data in a db with my own code. Much of this is a result of my feelings that if whatever site I create grows to a point of needing a server farm, then the session handling can make the leap without trouble.
That's funny, I use PHP sessions due to my feelings that if my site ever grows to the point of needing a server farm I can pay someone else to make sure the session handling makes the leap since the site will be making $ at that point...rofl

Posted: Fri Jan 10, 2003 11:38 am
by BDKR
Elmseeker wrote: That's funny, I use PHP sessions due to my feelings that if my site ever grows to the point of needing a server farm I can pay someone else to make sure the session handling makes the leap since the site will be making $ at that point...rofl
Yeah, and when they foul it up, how many dollars will you loose?

Doh!

Cheers,
BDKR