Trying to setup a sandbox development environment on my laptop before traveling for the holidays.  Found WAMP which was a breeze to setup and get running.

Anyway, I ran into a problem where basic session code that my servers handled fine wasn't working as expected when accessed via localhost.  This is how I got things working:

Set ALL session configuration parameters BEFORE calling session_name() (which, additionally, should ALWAYS be called before session_start(), fyi).  This includes, most importantly, session cookie parameters.  The following is one example that would work for either localhost or operating on a production server:

function domainName()
{
	$serverName = $_SERVER['SERVER_NAME'];
	$serverNameParts = explode('.', $serverName);
	if(count($serverNameParts) < 2) {
		return $serverName;
	} else {
		return $serverNameParts[count($serverNameParts) - 2].'.'.
			$serverNameParts[count($serverNameParts) - 1];
	}
}

function cookieDomainName()
{
	$domain = domainName();

	// if we're operating on localhost, provide a blank domain
	// otherwise cookies won't be set
	return ($domain == 'localhost') ? '' : '.'.$domain;
}

session_set_cookie_params(0, '/', cookieDomainName());
session_name('mySessionName');
session_start();

Hope this helps!

Related posts:

  1. PHP Custom MySQL Session Handler
  2. PHP fast, large (megabyte), data transfer between sessions
  3. PHP Dynamic JavaScript SCRIPT Insertion for Embedding
  4. PHP Array to String
  5. PHP Named Parameters