Page 1 of 1

Outdated PHP delimiters

Posted: Wed Mar 14, 2007 1:45 pm
by maxd
Hello, all.

A quick question about PHP delimiters. A client is prepping to migrate their site from one server to another, and it just occurred to me that I've noticed a lot of PHP code with only the <? delimiter, ie:

Code: Select all

<? 
//code 
?>
Rather than:

Code: Select all

<?php
// code
?>
It seems to me that model doesn't work on PHP 5 installs, which I imagine the new server will have.

Am I right about that?

Thanks,
max

Posted: Wed Mar 14, 2007 2:06 pm
by feyd
If the PHP 5 install has short_open_tag on, they will work. However I would suggest fixing the code over turning the setting on.

Posted: Wed Mar 14, 2007 4:42 pm
by Xoligy
A simple regexp file search and replace should do it. If you have a good IDE you should be able to do it from there.

Thanks

Posted: Wed Mar 14, 2007 9:54 pm
by maxd
I was thinking I could perform a global find and replace with BBEdit (my editor of choice). This is a massive site, and my initial search found nearly 3000 instances of the code in question. So, definitely something I want to tackle BEFORE deployment to the new server, so I can do a local search.

Are there any other code issues I should search for to make sure the site will function on newer versions of PHP?

I appreciate any tips.

Posted: Wed Mar 14, 2007 10:01 pm
by feyd
register globals, session problems, classes using "var," magic quote conflicts are a few that come to mind.

Posted: Thu Mar 15, 2007 12:38 am
by maxd
Thanks, feyd.

I'll poke around and see if there's a hint of any of those in play. As I said, the site is over 1,000 pages. They really only used PHP for includes and the like (hence, the enormous size), so I'm hoping we'll be OK.

Posted: Thu Mar 15, 2007 5:14 am
by stereofrog
You can also turn on any settings you need in .htaccess instead of wasting your time on editing 1000+ files.

Posted: Thu Mar 15, 2007 6:47 am
by mentor
stereofrog wrote:You can also turn on any settings you need in .htaccess instead of wasting your time on editing 1000+ files.
This is a better option.


Here is the list of all php.ini directives
http://www.php.net/manual/en/ini.php

To allow short php delimeters simply create a file named ".htaccess" and put the below code to change settings

php_value short_open_tag 1

Posted: Thu Mar 15, 2007 2:32 pm
by RobertGonzalez
Dudes, that is totally the wrong approach. feyd already mentioned it, and I will reiterate it, do not make your PHP5 installation that same insecure, outdated crap that a PHP3 install would be. Would you turn on register_globals just so your code will work, or will you make your code better so it will work on a more secure setup?

Leave short tags off. Leave register_globals off. If this is a production system, turn off display_errors and display_startup_errors. You might also want to lower your error_reporting from E_ALL (or E_STRICT in PHP5) to E_ALL ~ E_NOTICE to prevent unwanted notice level reports form spashing to the screen. If you are talking to a Sybase or MSSQL server database, raise your database error severity levels to 16 from the default 11 to prevent changing context notices.

Then, after checking into the things feyd has stated, make sure you check your code for objects that are passed by reference, as PHP5 does not like that much. Also, make sure the appropriate extensions are loaded on the new server so that any extension used on the old server are maintained (so your code doesn't break because of an extension issue).