1

So I have a PHP function that sets a session variable as follows:

function createSVar($varext) { 
 [...]
 $_SESSION['v'.$varext) = time(); // hypothetical value set
 [...]
 return $output;
}

And functions that call it:

function someFunction1() { 
 [...]
 $output = createSVar("name1");
 [...]
 return $output;
}

function someFunction2() { 
 [...]
 $output = createSVar("name2");
 [...]
 return $output;
}

These function is contained in a functions file. Then I have a config file setup as follows:

<?
ob_start();
session_name("mysession");
session_start();
[...]
include("functions.php");

Then on my PHP pages these are used as follows:

<?
include("config.php");
[...]
echo someFunction2();
[...]
echo someFunction1();

My problem is that this setup works fine on two different machines with PHP 5.2.17. On the third one with PHP 5.3.0, it doesn't. For some reason, it changes the previous session values (for the previously set session variable) on each call of the createSVar() function. I checked the changelog and didn't see any updates.

Could this be a bug?

hakre
  • 193,403
  • 52
  • 435
  • 836
0pt1m1z3
  • 841
  • 3
  • 12
  • 23
  • have you compared the ini files for both environments? any differences? – erickthered Feb 05 '13 at 03:54
  • I can generate a phpinfo() on either environments, but I don't have direct access to the INI files. Should I be looking for something in particular that could cause this issue? There's a lot of info there... – 0pt1m1z3 Feb 05 '13 at 03:55
  • 1
    yeah! it can be quite overwhelming and there's no magic answer. There are many things you can check like 'Register Globals' (which is obsolete since PHP 5.3), or maybe session.* settings. You could also add var_dump() and echo() to trace your script's flow or you could set error_reporting(E_ALL) to make sure you don't have any errors. Also, make sure your script doesn't depend on any of this: http://www.php.net/manual/en/migration53.deprecated.php – erickthered Feb 05 '13 at 04:07
  • Quick shot: Short open tags: `` - see: [Are PHP short tags acceptable to use?](http://stackoverflow.com/q/200640/367456?r=0) and [How to enable PHP short tags?](http://stackoverflow.com/q/2185320/367456?r=0) – hakre Mar 31 '13 at 10:25

1 Answers1

0

My first inclination is to have the ob_start() called after the session_start(). Session_start() requires sending HTTP headers which may be getting buffered by the ob_start() call.

ajacian81
  • 7,419
  • 9
  • 51
  • 64
  • Nope. No luck with that change. Like I said, it works fine on two different hosting providers with 5.2.17. – 0pt1m1z3 Feb 05 '13 at 03:45
  • This is more a comment than an answer. From what is normally technically known, output buffering should not conflict with `session_start()` in any way. – hakre Mar 31 '13 at 10:21