Solved

PHP files showing as text in Internet Explorer

Posted on 2006-11-24
25
320 Views
Last Modified: 2012-06-27
Hi

I have moved a folder containing php scripts from one server to another and on the same day my Internet Explorer upgraded to v7 as part of a Windows update. Before moving it, it worked fine but now, when I click a "login" button having entered my username and password, the next thing to display in my browser is the raw php code as a text file! Very annoying and not very secure either! (not that passwords are contained in it).

Both servers are PHP enabled and nothing has changed recently regarding that. The server the files are currently on is definitely PHP enabled because it has a script that is scheduled to run every Monday morning which emails our customers. This works, because undeliverable ones come to me, and customers often call about the mails we're sending.

I'm sure I've seen this before but can't remember what to do. I'm also wondering if it's anything to do with the IE upgrade. To be sure, I installed FireFox 2 and that does a similar thing although doesn't show the entire code.

Thanks in advance
DC
0
Comment
Question by:davidcowler
  • 7
  • 7
  • 6
  • +1
25 Comments
 
LVL 11

Expert Comment

by:ch2
ID: 18007895
Make sure your php tag is like this <?php ?>
0
 
LVL 5

Expert Comment

by:burningmace
ID: 18007960
Some servers allow short tags like this:
<?
?>

If you've moved to a new server and were using short tags, you should either:
* Replace the short tags (<?, etc) with full tags (<?php, etc)
Or
* Change (or ask the admin to change) your PHP configuration so that short tags are enabled.

Chances are it's not an issue with IE, more an issue with the server's PHP config. If the problem continues, try the page in other browsers such as Firefox and Opera. If you get the code in text, then you've got a server issue. If it works in FF and Opera, but not IE, something more sinister is going on. Knowing IE's history, I wouldn't be surprised.
0
 
LVL 1

Author Comment

by:davidcowler
ID: 18007963
Forgot to mention - the scripts that run automatically just access a database and then send emails. There is no web or html page involved.

Thanks
DC
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18007964
If your seeing Raw PHP source in your code then it is NOT IE7

IE7 doesent read the source code it is only ever run and executed by your sever and HTML/TEXT/OTHER is returned as a result. No Direct PHP source code is ever shown.

I would suggest its a problem with the PHP setup on your new server can I ask what type of Web Server your using?

0
 
LVL 5

Expert Comment

by:burningmace
ID: 18007977
Also, if you're making PHP pages which are partially HTML (e.g <html><body><?php echo 'Something'; ?></body></html>) you should make sure that the first thing in the document is a <?php ?> block.

Some installations have a problem with having that missing, for example the following will fail:

<html>
  <head>
    <title>Test</title>
  </head>
  <body>
    <?php echo 'Something'; ?>
  </body>
</html>

But if you put <?php ?> at the start (before the <html> tag) the code will work fine.
0
 
LVL 1

Author Comment

by:davidcowler
ID: 18007985
I'm no expert on setting up PHP (never done it) but I know it's running under Apache on a Windows 2003 server.
0
 
LVL 5

Accepted Solution

by:
burningmace earned 75 total points
ID: 18007998
If you are running Apache, you may not have the correct handler types set up.

Make sure that you have the following in your httpd.conf:

AddType application/x-httpd-php .php
PHPIniDir "C:/Program Files/Apache Group/Apache2/PHP"

This tells the server that .php files are application/x-httpd-php, which PHP then picks up on and processes properly. Without this directive, the server will simply look at the encoding of the file and attempt to output it as text/plain.
0
 
LVL 13

Assisted Solution

by:rhickmott
rhickmott earned 75 total points
ID: 18008000
Ok if its a new server then the issue is more likely to be caused by an incorrect PHP set-up.

Normally for security reasons if the PHP module is running correctly it will show NO output as opposed to the source which soudns to me like the module is not being loaded properly.

Firstly see if you have the Apache Monitor installed (Its in the task bar its a circle with a little play icon in it and a red tail thing) double click it and at the bottom it should say something along the lines of

Apache / x.x.x ( Win32 ) PHP x.x.x

That last bit is important if there's no PHP part then its not running the PHP module if it is then post back and were go from there :)

0
 
LVL 5

Expert Comment

by:burningmace
ID: 18008017
Oh, and just to note, you need to alter the PHPIniDir to the correct directory for your PHP installation (e.g C:/PHP or C:/PHP5/PHP.
0
 
LVL 1

Author Comment

by:davidcowler
ID: 18008101
Ok, done some checking around.

burningmace:
----------------
AddType application/x-httpd-php .php
PHPIniDir "C:/Program Files/Apache Group/Apache2/PHP"

The AddType line is in that file but the PHPIniDir line is not. Where should it be added?

rhickmott:
------------
I don't have that icon. I'm RDPd into the server as Administrator but the icon isn't there. Can I run it manually? If so, how?

Thanks guys
DC
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18008110
The PHPIniDir should be included under the AddType command.

And the program you want is called ApacheMonitor.exe it should be located under your Apache Bin Folder.
0
 
LVL 11

Expert Comment

by:ch2
ID: 18008223
Look at %windir% if there is a php.ini.

Windir is the first place php try to locate php.ini.

Open php.ini and search for this. Change the value short_open_tag to on, and try if php works

; Allow the <? tag.  Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = Off
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 13

Expert Comment

by:rhickmott
ID: 18008241
Look in your httpd.conf file for a line similar to

LoadModule php5_module "C:/php/php5apache2.dll"

This is the most vital line as it tells Apache to Load the PHP Module.

Im assuming your using PHP5? If so it will depend on your version of Apache

Use

LoadModule php5_module "C:/www/php/php5apache.dll"            For Apache 1.3.x
LoadModule php5_module "C:/www/php/php5apache2.dll"           For Apache 2.0.x
LoadModule php5_module "C:/www/php/php5apache2_2.dll"       For Apache 2.2.x

If your using Apache 2.2.x you MUST have PHP 5.2.0.

If your using PHP 4 then you will need to change your paths to php4apache respectively.
0
 
LVL 5

Expert Comment

by:burningmace
ID: 18008252
Use Ctrl-F (Search/Find) in notepad to look for PHPIniDir in httpd.conf

If it's not there, add it after the AddType directive you found.
0
 
LVL 11

Expert Comment

by:ch2
ID: 18008263
A php conf file for windows

LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"

<IfModule php5_module>
      PHPIniDir "F:/conf"
      <Location />
            AddType text/html .php .phps
            AddHandler application/x-httpd-php .php
            AddHandler application/x-httpd-php-source .phps      
      </Location>

</IfModule>
0
 
LVL 5

Expert Comment

by:burningmace
ID: 18008269
Remember, you must restart the Apache service to update your config.

You can do this using the Apache Service Monitor (if you enabled it, it will show the apache icon in your system tray) or via the service control page (Start->Run... type 'services.msc', no quotes). Find the Apache service, right click it, click "Restart".
0
 
LVL 5

Expert Comment

by:burningmace
ID: 18008308
As an example, my server's Apache configuration is as follows, with Apache 2.0 and PHP5:

Under the loadmodule section, you need:
LoadModule php5_module E:/PHP/php5apache2.dll

Look for "DirectoryIndex" and add index.php to it, so that Apache recognises it as a valid index.
DirectoryIndex index.html index.html.var index.php

With all of the AddHandler directives:
AddType application/x-httpd-php .php
PHPIniDir "E:/PHP"

Replace "E:/PHP" with whatever your PHP directory is.
0
 
LVL 1

Author Comment

by:davidcowler
ID: 18008412
burningmace:
----------------
Ok, my php.ini is in c:\windows so I'm thinking the PHPIniDir line might confuse things, unless I change its path to c:\windows. But ch2 says that's the first place PHP looks, so I should be ok. Or should I move it?

rhickmott:
------------
the Loadmodule line DOES exist so that's fine.
I think we have PHP 4 - can't check easily because the php 'info' command won't run, of course! The line you mention does actually say PHP5 though so I'm not sure now!
We have Apache v 2.0.52.

0
 
LVL 11

Expert Comment

by:ch2
ID: 18008446
if you have your php.ini in windows don't use phpinidir directive or if use it have to point to where you move the ini file.

Also make sure this directive is also set to on in the ini file.

engine = On
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18008464
If you look in the PHP folder and have phpapache5.dll then its most likely PHP5.

If not you prob change the line to

LoadModule php4_module "C:/php/php4apache2.dll"  

Depending on what version of HP you have.

You dont actually *need* a php.ini php will initalise without a php.ini using the default settings so I dont think your core problem is releated to php.ini
0
 
LVL 1

Author Comment

by:davidcowler
ID: 18008525
All the DLLs have '5' in the filenames so I guess I have PHP 5.something.

The only thing from the list above that I haven't done is ch2's 'engine' line. I don't have one in my httpd.conf file. What does it do and where should I put it?

The 'DirectoryIndex' section is also setup correctly, by the way. Obviously not a straightforward problem, so points increased a little.

Thanks.
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18008532
That is a php.ini Line irrr.

Can you post up your httpd.conf file and the location of your php installation folder.
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18008540
If you want to find out your php version open a command line window and go to your php installation folder

create a file called phpinfo.php in your PHP Folder with

=============
<?php
   phpinfo();
?>
=============

enter the command

php.exe phpinfo.php > phpinfo.txt

That will dump any relevant information about your version of PHP
0
 
LVL 11

Expert Comment

by:ch2
ID: 18008678
Don't get confused.

httpd.conf  = Apache Configuration
php.ini     =      PHP initialization.

//php.ini
engine = On

//if your php scripts tag opend with <? set this directive to on
short_open_tag = Off

Also make sure you don't have an errors in your script, so look at your apache error logs. or set those directives:

// php.ini
error_reporting  =  E_ALL
display_errors = On
0
 
LVL 1

Author Comment

by:davidcowler
ID: 18088652
The answer was... the server was not set up as a webserver. PHP is installed and is used for batch files, as I mentioned, but wasn't set up to handle browser requests. Now, I don't know exactly what our IT guy did to make it work, and I don't know if his solution is something mentioned in the repsonses. So I'm splitting the points between burningmace and rhickmott.

Cheers guys.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now