PHP scripts and games

So I’ve been adding a few RPGs and other games to the site and have had to edit those scripts quite a lot more than I should have to to get them to work on my site. Don’t get me wrong (especially if you happen to be a creator of one of those scripts), I love the games, and they have MANY good features in them, but it amazes me how much people code to their own setup. One example (and the most annoying because it breaks the script immediately), is the use of PHP short tags ( <? ). These little things are the bane of my existance.

There are four ways that you can let the server know that you are about to use PHP.

  • PHP Long tags ( <?php ...code... ?> )
  • PHP Short tags ( <? ...code... ?> )
  • ASP style tags ( <% ...code... %> )
  • Script tags ( <script language="text/php"> ...code... </script> )

Lucky for me, I’ve never seen the ASP tags, and have only rarely seen the Script tag, but the short tags are almost as popular as the long tags. Especially when using the shorthand notation for the echo command ( <?= ).

My server at home is set up to be very strict in it’s handling of tags, it only allows the PHP long tags, and for good reason. When using a PHP script with XML, the XML tag ( <?xml ) confuses the PHP parser into thinking it’s a PHP short tag with the unknown entity ‘xml’ following it.

Another thing I see people use often, is Registered Globals. These are extremely handy at saving yourself some keystrokes, but that’s about the only thing they are good for. Registered Globals take variables from a SuperGlobal and place it in the normal variable scope. An example would be an HTML form with a field called ‘name’.  When you send this form, a variable in PHP called either _POST or _GET is created based on which method is used to send the data. To get at the data the user sent, one must call $_POST['name'].  If Registered Globals is turned on, all one needs to do is call the variable $name and there ya go. This practice is not very safe and causes more headaches then they save in keystrokes.

All of these issues, plus some more obscure ones, are why people should not code to their own particular setup, but should code with certain standards that are applicable everywhere.

  • PHP Long tags are ALWAYS accepted by the server.
  • The _POST and _GET variables are ALWAYS available to the script.
  • The HTTP_XXXXX_VARS are NOT always available, as of PHP5 they can be disabled.
  • Even the _ENV and _SERVER vars are not always enabled.

So when you go out to write your first bit of code, or even continue work on a project you’ve been working on for years, think of the other people who may be using your script who may not have the same setup as you, and they may not have access to their php.ini file to change those settings. And don’t try to skirt your way around it by running the ini_set function either. That’s almost like putting a virus on someone else’s computer. Just don’t do it.

One Reply to “PHP scripts and games”

  1. Any chance of getting a copy of the fixed versions of these games? I’m particularly interested in NetRisk- I’m running into a few annoying bugs with my version of the game-

    Thanks!

Comments are closed.