PHP AND GLOBAL VARIABLES (CHANGING SERVERS)

TUESDAY, FEBRUARY 17 2004 @ 01:02 AM

I've changed servers over the weekend, and by now propagation should be complete. The funny thing is that for a moment in the afternoon, the site was apparently broken, since most of the rendering scripts weren't working. I got real worried for a while, until I found the answer: newer installations of PHP (4.2 and on) don't set environment variables as globals.

I have to be one of the worst organized coders around, although I try to make code look organized. The sad true is that most of the core scripts on my blog system were written in a very amateurish style, since I actually learned PHP programming when building this thing. then I patched it over an over again... and well, never took care of certain details, some times I'm just too lazy :)

So, this morning, instead of just turning
//1<\/div> back 'On', I decided to finally get dirty and fixed all my scripts to look for data in just the right places. I also took advantage of the situation and added a couple of features I wanted in the blog for a while now, like showing the number of times a post has been viewed; it will be useful later to keep track of the most popular posts, and stuff like that.

So, regarding the server changes, some may have experienced delays and/or 404 errors during this period. Also, if someone sent me an email and it got bounced back, I apologize for the inconvenience: I'm still here :)

Archived under: PHP. | Permalink | google | del.icio.us Is it delicious? | digg Do you digg it?


CHRIS

FEBRUARY 17 2004 @ 09:11 AM

you can use this little script to initialize your variables

foreach($HTTP_POST_VARS as $key=>$ele){
$this->$key = $ele;
}

OSCAR TRELLES

FEBRUARY 17 2004 @ 04:41 PM

Nice. That would have saved me quite a few minutes.

Then again, it is always better to comply with best practices, when at all possible. That's what that change in PHP's default installation is encouraging.