PHP, AJAX, and global variables

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
oldsportbiker
Forum Newbie
Posts: 7
Joined: Wed Feb 24, 2010 10:21 pm

PHP, AJAX, and global variables

Post by oldsportbiker »

Before I start my first Ajax coding effort, I thought I'd confirm my understanding of PHP global variables and sessions. It seems to me , from what I've read, that when I execute a php script from Javascript, that I need to provide that php script with everything it needs as it will not have access to already established global variable or session values, nor will it be able to use the database connection established by the php script that rendered the page from which the javascript will run. Said more simply, I'll have to have every php script that I run from Javascript:
1. start a session
2. establish a database connection
3. logon to the database
4. provide SQL every individual column value that it needs for both select and/or update.

Do I have this right?
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: PHP, AJAX, and global variables

Post by PHPHorizons »

That's pretty much what you need to do.

I design my sites so that the script that handles regular page requests also handles the ajax page requests. I add a variable to the url that instructs the script to omit the header and footer.

Hope that helps.
Post Reply