3

IIS is literally sending <?php ... ?> code to the browser rather then executing it.

But, only for the root http://domain.com/index.php file.

All other .php files in that folder and index.php files in subfolders execute as expected.

How can I get my root index.php code to execute?


Update: "index.php" is a Default Document of my Web Site...

alt text http://img412.imageshack.us/img412/4130/defaultdocumentmt9.gif

5
  • Did you check for the default document in the root? Commented Oct 9, 2008 at 19:44
  • "index.php" is a Default Document of my Web Site Commented Oct 9, 2008 at 19:53
  • Are you sure the PHP extension is loaded? Commented Oct 9, 2008 at 20:10
  • All other .php files in that folder and index.php files in subfolders execute as expected. Commented Oct 9, 2008 at 20:39
  • did you ever identify a root cause of this issue? Commented Oct 7, 2011 at 3:44

5 Answers 5

4

It seems you have properly configured your handlers. If you're using <? ... ?> make sure you have short_open_tag = On in your php.ini.

Sign up to request clarification or add additional context in comments.

2 Comments

Neither <?php tag nor <? short tag code executes. But short_open_tag is on, for what it's worth.
Have you tried with only <?php echo("Hello"); ?> in the file? Just can't imagine another thing right now.
4

I was having this issue and ultimately tracked down the source to be the encoding of the PHP file. Apparently I had set my editor to use Unicode (2-byte unicode, not UTF-8) as the encoding. This causes PHP not to see the <? tags, but the browser seems to be able to read the Unicode file just fine, so viewing source reveals the actual PHP code. (Even though the file had a content-type=utf-8 meta tag!) Saving the PHP file in ANSI or UTF-8 encoding solved the problem.

Lots of debugging went into finding that simple solution, so I thought I'd add it here for anyone else who has this problem.

An interesting side-effect of the problem was that Firefox and Chrome didn't seem load the CSS file. Upon further examination, I found that browsers are supposed to assume the same encoding for CSS as for HTML, unless explicitly specified in the CSS file. Viewing the CSS in Chrome or Firefox would show Chinese characters! This helped lead me to the solution, actually.

Comments

3

UPDATED: I have found a few possible workarounds for PHP 5 and IIS 7. If those solutions are not working, please provide more details about your index.php, IIS setup, or try to use IIS 6 compatibility.

2 Comments

For the sake of having the information here on Stack Overflow, could you summarize those postings? Thanks.
Not to drudge up an 8 year old post, but as @ThomasOwens said... can you sum up the links? I cannot access the 'Problem with PHP Includes on IIS7' link at work.
2

Have you tried bouncing (stop/restart) IIS? Maybe even restarting the machine? I know there have been times when I've done some IIS configuration changes that I would have sworn should have only needed only a bounce to take effect that didn't get going until a full machine restart.

Comments

1

All though this is an old question, over 11 years later this is still an issue. My work around was to create default.aspx file and perform a redirect from within it. Save the file to the root directory of your website and add default.aspx to the default documents in IIS. Make sure you move it to the top of the list to prioritize it to be processed first. The below code is what I used.

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected override void OnLoad(EventArgs e) {
    Response.Redirect("index.php");
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Title Of Your Website Here</title>
</head>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.