* * * * *
Reason #3.1415926 I hate PHP
Continuing with the PHP woes [1], this time it seemed that PHP wasn't
tracking session data. I started to look into this given the minimal script
that was provided to prove the problem.
Yup, looked like it wasn't keeping track of the session. Taking a look at the
code:
-----[ PHP ]-----
<?php
session_register("yword");
session_register("se");
if (!$yword){
$wordtext = "Sorry i can't get the session";
}
else
$wordtext = $yword;
if (!$se){
$setext = "No";
}
else
$setext = $se;
?>
-----[ END OF LINE ]-----
Started reading the documentation for the session_register() function:
> bool **session_register** ( mixed name [, mixed …])
>
> **session_register()** accepts a variable number of arguments, any of which
> can be either a string holding the name of a variable or an array
> consisting of variable names or other arrays. For each name,
> **session_register()** registers the global variable with that name in the
> current session.
>
> Caution
>
> If you want your script to work regardless of register_globals [2], you
> need to instead use the $_SESSION [3] array as $_SESSION entries are
> automatically registered. If your script uses **session_register()**, it
> will not work in environments where the PHP directive register_globals [4]
> is disabled.
>
> **register_globals: important note:** Since PHP 4.2.0, the default value
> for the PHP directive register_globals [5] is off. The PHP community
> encourages all to not rely on this directive but instead use other means,
> such as the super globals [6].
>
“PHP: session_register [7]”
Not only are they using the wrong function for what they want, but even if it
did work, you're not really supposed to use that function anymore, because,
you know, it's obsolete (I mean, that's so PHP 4.1.2).
Language du jour I'm telling you! How can anyone use a language with such
drastic changes from year to year (or even day to day)? I'm not even going to
mention variable variables [8] (it's not that variables in PHP aren't
variable enough, it's that this is the PHP way to doing pointers in a
langauge that doesn't support pointers but I said I wouldn't mention it, so I
won't).
Anyway, the solution to the problem above was to change the code so it looked
like:
-----[ PHP ]-----
<?php
$yword = $_SESSION['yword'];
$se = $_SESSION['se'];
..
-----[ END OF LINE ]-----
And all was right with the world.
Well … almost.
They're still using PHP, which makes using Perl seem almost logical …
[1]
gopher://gopher.conman.org/0Phlog:2004/11/11.3
[2]
http://us2.php.net/manual/en/ini.sect.data-handling.php#ini.register-globals
[3]
http://us2.php.net/manual/en/reserved.variables.php#reserved.variables.session
[4]
http://us2.php.net/manual/en/ini.sect.data-handling.php#ini.register-globals
[5]
http://us2.php.net/manual/en/ini.sect.data-handling.php#ini.register-globals
[6]
http://us2.php.net/manual/en/language.variables.predefined.php
[7]
http://us2.php.net/function.session_register
[8]
http://us2.php.net/manual/en/language.variables.variable.php
Email author at
[email protected]