PHP5 Displays Source Code

PHP5 won't process php files and displays source code

Page 1 of 1

7 Replies - 5597 Views - Last Post: 20 May 2008 - 05:32 PM

#1 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 797
  • Joined: 25-February 08

PHP5 Displays Source Code

Post icon  Posted 15 May 2008 - 03:13 PM

Hey Everybody,

I was contracted to help work on a php program, but I'm having trouble getting my PHP 5 version to work with their program.

I am running WAMP, with Apache version 2.2.8 and PHP 5 version 5.2.6

I also have PHP 4 installed with Apache 2.0.63. The nice thing about wamp is that you can go back and forth between versions of Apache and PHP 4, without any hassles. That's the theory at least.

If I'm running PHP 4 I can go to the directory that my index file is in, and the page will start to generate. I get an undefined function error, because the function is only available in PHP 5. No problems. I switch over to my Apache 2.2.8 and PHP 5.2.6, restart the services, and attempt to refresh the page. At this point the page no longer generates and I'm greeted with a blank white screen. I view the source, and it's all my PHP source code.

My initial idea was that my httpd.conf and php.ini files were messed up. I checked them out, and everything looks fine. I decided to set up a simple php info page as follows.

<?php
	 echo phpinfo();
?>



Everything runs fine and I'm told that I'm running PHP 5.2.6. Then I make another page with various php functions, and everything works fine. So PHP 5 is running without any problems.

So now I need to figure out why I'm not getting the other page generated. It should be noted that the other page is in a SVN repository, but that shouldn't make any difference. The pages still load with no problems. I'm also pulling from an Oracle database, but I can connect and everything with no problems.

Thanks for any guidance you can give. Just to sum up, my problem is that running php 5 on my //localhost/ is resulting in a blank page with php source code. And before it's asked yes, I am accessing the file via //localhost/ and not c:\.

Thanks again everyone.

Koz

Is This A Good Question/Topic? 0
  • +

Replies To: PHP5 Displays Source Code

#2 no2pencil  Icon User is online

  • Dic Head
  • member icon

Reputation: 5167
  • View blog
  • Posts: 26,849
  • Joined: 10-May 07

Re: PHP5 Displays Source Code

Posted 15 May 2008 - 08:50 PM

In the new version of Apache, is php enabled as a file type?

AddType application/x-httpd-php .php


Was This Post Helpful? 0
  • +
  • -

#3 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: PHP5 Displays Source Code

Posted 15 May 2008 - 11:54 PM

View Postno2pencil, on 15 May, 2008 - 08:50 PM, said:

In the new version of Apache, is php enabled as a file type?

AddType application/x-httpd-php .php




Yes I have my AddType set up. I also have my LoadModule working and my DirIni (sic? it's correct in the httpd.conf) working. I'm trying to figure out why the php will render in one file, but not in another. It's so odd. Any other suggestions?
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Dic Head
  • member icon

Reputation: 5167
  • View blog
  • Posts: 26,849
  • Joined: 10-May 07

Re: PHP5 Displays Source Code

Posted 15 May 2008 - 11:58 PM

View Postakozlik, on 16 May, 2008 - 02:54 AM, said:

I'm trying to figure out why the php will render in one file, but not in another.

Is it possible for you to post those two files? Or at least enough of them to get a good idea for trouble shooting?
Was This Post Helpful? 0
  • +
  • -

#5 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: PHP5 Displays Source Code

Posted 16 May 2008 - 11:20 AM

View Postno2pencil, on 15 May, 2008 - 11:58 PM, said:

Is it possible for you to post those two files? Or at least enough of them to get a good idea for trouble shooting?


Well the file that works only contains

<?php

echo "Hi!";
echo phpinfo();

?>

The other file I really can't post since I'm under contract and don't own the copyright. I know that the file works though, because when I'm running php 4 it generates the site, it just doesn't populate it with the data because it needs php 5. It's a strange problem isn't it?

Andrew
Was This Post Helpful? 0
  • +
  • -

#6 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: PHP5 Displays Source Code

Posted 16 May 2008 - 08:58 PM

I figured out what the problem was. Unfortunately I couldn't post my source, so we wouldn't have figured it out there.

For future reference, the problem was that my short_open_tag property was set to Off. If you're reading this post and you're having the same problem, you can fix it by going into your php.ini file and looking for 'short_open_tag'. It probably says short_open_tag = Off. You need it to say On. Otherwise, any php contained between

<? ?> tags won't be run. Thanks for the help though!
Was This Post Helpful? 0
  • +
  • -

#7 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: PHP5 Displays Source Code

Posted 20 May 2008 - 04:03 PM

Ah - that's a common issue.

The easiest way to get around it, I find, is to just always use <?php ?>, without the shorthand.
Was This Post Helpful? 0
  • +
  • -

#8 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: PHP5 Displays Source Code

Posted 20 May 2008 - 05:32 PM

View Postgirasquid, on 20 May, 2008 - 04:03 PM, said:

Ah - that's a common issue.

The easiest way to get around it, I find, is to just always use <?php ?>, without the shorthand.


I definitely agree. The problem was that I was using source code written by a client who contracted me to add on to the preexisting code. There were a lot of <? ?> statements that were used, so it was a time thing as far as changing all instances to <?php. Regardless, the problem's solved now and I'm back to work.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1