Page 1 of 1

> (greater than) recognized as end tag in php5 with apach

Posted: Mon Jun 25, 2007 10:16 pm
by martinco
hi!

i've recently installed apache2 and php5 locally on my computer, and installed a open source gallery.
in the source code there's a grater than comparisson between a variable and a number, but the > is recognized as an end tag :x (as if in the older version PHP/FI 2.0, see http://www2.stack.ru/~julia/PHP4/migration.php3.html).
the rest of the script after the grater than character if printed out in the document as html.
what can i do to prevent this from happening?
is there something to configure in the installation of apache or php?

thanks!

Posted: Mon Jun 25, 2007 11:30 pm
by superdezign
Is there a question mark attached to that greater than sign by any chance?

Otherwise, you sure your PHP 5 installation is configured correctly? Run phpinfo().

Posted: Mon Jun 25, 2007 11:37 pm
by Benjamin
PHP 5 will not recognize a > as a closing tag.

Code: Select all

echo (10 > 20) ? 'test' : 'test';
Post the code & or exact error.

Posted: Tue Jun 26, 2007 1:07 am
by martinco
that simple test with echo perfectly works.

the gallery i installed is plogger (open source). i've installed it in a server via ftp before and worked perfectly. the think here has to do with my apache or php configuration, not with the script.

the script that causes the error is contained in the source file \lib\exifer1_4\exif.php of plogger. That file if called by the function require_one(...) in a file (admin\plog-admin-functions.php) that was called by include(...) in the file shown by the browser (admin\plog-upload.php and many others).

the 'grater than' character appears in the line 336 of exif.php :

Code: Select all

if($type=="SRATIONAL" && $top>2147483647) $top = $top - 4294967296;
all the script after that '>' is printed on the document "2147483647) $top = $top - 4294967296; //this makes the number signed instead of unsigned if($bottom!=0) $data=$top/$bottom; else if($top==0) $data = 0;" etc etc etc etc.... and after the end of the script comes the rest of the page.

Posted: Tue Jun 26, 2007 1:12 am
by Benjamin
That makes no sense at all.

What happens if you change the line to...

Code: Select all

if ($type == "SRATIONAL" && ($top > 2147483647)) { $top = $top - 4294967296; }

Posted: Tue Jun 26, 2007 3:51 am
by volka
I guess the browser got the whole code and interpreted > as the end of one html tag.
Take a closer look at your opening tags. Do you use <? or <?php ?
Or is there by any chance a space between < and ? ?

Posted: Tue Jun 26, 2007 5:52 am
by vigge89
Argh, I've read about this issue before but can't remember where it was posted. I think it happens when your apache/php config has set it's start and end tags to <? and > but I'm not sure. I bet someone else here can shed a light onto this though.

Posted: Tue Jun 26, 2007 6:25 am
by volka
if short_open_tags are disabled and the script uses them, e.g.

Code: Select all

<? if (3 > 4) { echo "..."; } ?>
then the whole script's code will be sent to the browser.
And the browser will interpret <? if (3 > as an broken tag/processing instruction and the rest is just text.

Posted: Tue Jun 26, 2007 7:59 am
by superdezign
Run a regex enabled Find/Replace:

Code: Select all

Find: <\?(?!php|=)
Replace: <?php

Code: Select all

Find: <\?=
Replace: <?php echo
There an extra space at end of the second one, so be sure to add it.

Posted: Tue Jun 26, 2007 2:24 pm
by martinco
now it works!! :D

in my php configuration the short_open_tag attribute was Off.
i'd read about it and decided to give it the default value (off). but now i see that the script that was bottering me uses short tags <? ... > :x

i decided to change my php configuration turning short_open_tag On instead of editing the original script.

"Pura vida!"

Posted: Tue Jun 26, 2007 2:28 pm
by superdezign
I'd highly suggest you don't. I believe short tags will be completely removed as of PHP6, so get used to not using them ASAP. I gave you the regex you need to remove them all. I had to do it once on someone else's files.