Saturday, November 13, 2004
Reason #3.1415926 I hate PHP
Continuing with the PHP woes, 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 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; ?>
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, you need to instead use the $_SESSION 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 is disabled.
register_globals: important note: Since PHP 4.2.0, the default value for the PHP directive register_globals is off. The PHP community encourages all to not rely on this directive but instead use other means, such as the super globals.
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 (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 $yword = $_SESSION['yword']; $se = $_SESSION['se']; ...
And all was right with the world.
Well … almost.
They're still using PHP, which makes using Perl seem almost logical …