Site Broken in PHP 5.4 - Need help with changes (fixed)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Site Broken in PHP 5.4 - Need help with changes (fixed)

Post by Bigun »

I'm trying to step through the code and find the major changes. One of the first changes I noticed is the following code no longer works as expected:

Code: Select all

<?php
if (!isset($_SESSION['userid'])) {
	//No one is logged in, kick them back
	?>
	<div id="body">
	<center><span class="info">You are not logged in, please wait one moment while we redirect you</span></center>
	<meta http-equiv="refresh" content="2;url=./">
	</div>
	<?php
	include('../footer.php');
	exit();
}
Normally I can jump in and out of PHP code to post some HTML, but now it seems if I jump out that PHP completely loses its place. It gives an error saying the last bracket was unexpected.

*edit*

I did some more research and this seems to have happened between version 5.3.27 and versions 5.4 and breaks even worse in 5.5 (warnings about SQL queries).
Last edited by Bigun on Fri Aug 01, 2014 7:53 pm, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Site Broken in PHP 5.4 - Need help with changes

Post by Celauran »

That code by itself looks fine. Could you post a bit more of the surrounding code and the exact errors you're encountering?
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Re: Site Broken in PHP 5.4 - Need help with changes

Post by Bigun »

Only two lines before that:

Code: Select all

<?php
include('../header.php');
I can post some of header.php if it will help.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Site Broken in PHP 5.4 - Need help with changes

Post by Celauran »

The code you have posted is running fine on 5.4.7
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Re: Site Broken in PHP 5.4 - Need help with changes

Post by Bigun »

I figured it out, turns out the include file included use of the following tags:

Code: Select all

<?
Which is disabled by default in the php.ini(short_open_tag = Off).

Is there any known security risk with leaving short open tags on?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Site Broken in PHP 5.4 - Need help with changes (fixed)

Post by Celauran »

It's not a security risk that I'm aware of, but it's definitely a bad practice as, as you've seen, it reduces code portability. Many (most?) servers will have short tags disabled.
Post Reply