Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6889 > unrolled thread
| Started by | Jason C <jwcarlton@gmail.com> |
|---|---|
| First post | 2012-08-27 23:37 -0700 |
| Last post | 2012-08-28 17:42 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.php
Changing session variables gives warning Jason C <jwcarlton@gmail.com> - 2012-08-27 23:37 -0700
Re: Changing session variables gives warning "J.O. Aho" <user@example.net> - 2012-08-28 17:42 +0200
| From | Jason C <jwcarlton@gmail.com> |
|---|---|
| Date | 2012-08-27 23:37 -0700 |
| Subject | Changing session variables gives warning |
| Message-ID | <d38038b0-cb71-403b-93e5-c42916a571f7@googlegroups.com> |
I'm setting a series of SESSION variables, then on each page check to make sure one of those variables hasn't changed; if so, the script reloads them. The purpose is to limit the number of MySQL queries on an already taxed server.
I'm using a script like this:
if ($default != $_SESSION['default']) {
$var_query = sprintf("SELECT * FROM vars WHERE var='%s' LIMIT 1",
mysql_real_escape_string($default));
list($_SESSION['default'], ...) = mysql_fetch_row(mysql_query($var_query));
session_commit();
}
But now I get this warning in the log:
PHP Warning: session_commit() [<a href='function.session-commit'>function.session-commit</a>]: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in whatever.php on line 165
I'm using PHP 5.2.17.
Should I be changing these variables in a different way? Or is it perfectly safe to change the script to:
session_commit();
ini_set('session.bug_compat_warn', 0);
ini_set('session.bug_compat_42', 0);
[toc] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2012-08-28 17:42 +0200 |
| Message-ID | <aa476qFs0lU1@mid.individual.net> |
| In reply to | #6889 |
On 28/08/12 08:37, Jason C wrote:
> I'm setting a series of SESSION variables, then on each page check to make sure one of those variables hasn't changed; if so, the script reloads them. The purpose is to limit the number of MySQL queries on an already taxed server.
>
> I'm using a script like this:
>
> if ($default != $_SESSION['default']) {
> $var_query = sprintf("SELECT * FROM vars WHERE var='%s' LIMIT 1",
> mysql_real_escape_string($default));
>
> list($_SESSION['default'], ...) = mysql_fetch_row(mysql_query($var_query));
why not just select the column you want instead of the whole row?
> session_commit();
drop this line
> }
>
> But now I get this warning in the log:
>
> PHP Warning: session_commit() [<a href='function.session-commit'>function.session-commit</a>]: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in whatever.php on line 165
>
> I'm using PHP 5.2.17.
>
> Should I be changing these variables in a different way? Or is it perfectly safe to change the script to:
I would suggest you skip using the session_write_close() (for which
session_commit is an alias for), as it won't do much at all for PHP5.
> session_commit();
> ini_set('session.bug_compat_warn', 0);
> ini_set('session.bug_compat_42', 0);
To make this to suppress the message in the error log, you need to run
the ini_set before the session_write_close(), but then it's simpler just
to drop it.
--
//Aho
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web