NYCPHP Meetup

NYPHP.org

[nycphp-talk] $_SESSION, Logout, and Shared Host

Tim Lieberman tim_lists at o2group.com
Wed Nov 4 21:49:46 EST 2009


On Nov 4, 2009, at 9:19 PM, Christopher R. Merlo wrote:
> Judging from the errors I got, it seems like I may have to do that  
> before *every* call to session_start(), which is Big Oh of the  
> amount of work in adding a layer to $_SESSION.

True.  You've just learned a valuable lesson: You should only ever  
call session_start() in one place.  Typically, people it put it some  
file named something like "config.php", that gets included by every  
other page in the application.

>
> This should work nicely, unless you need to share session data with  
> your colleage's appication.
>
> No, we need to not share data with each other -- if you're  
> submitting assignments in ITE 101, you don't want to accidentally  
> overwrite what you already submitted for CSC 101, for example.

True enough.

>
> However, a global find/replace to replace $_SESSION with  
> $_SESSION['someKey'] will probably do the trick, and not be too  
> painful.
>
> Yeah, I can do that with find, xargs, and sed.  Thanks for the advice.

That's probably how I would do it.

I suggest you do *both*.  If you're repeating configuration stuff  
(session_start()) all over the place, you should be refactoring anyway.

Doing some fake namespacing in $_SESSION is a good idea, too.

I'd do both, but I'd refactor all of your configuration/bootstrapping  
first.



More information about the talk mailing list