问题描述:

I am not able to run a php script on an html page which looks like this:

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title>Directory Contents</title>

<link rel="stylesheet" href="stylesheets/displayStylesheet.css">

<script src="javascripts/sorttable.js"></script>

</head>

<body>

<div id="container">

<h1>Directory Contents</h1>

<table class="sortable">

<thead>

<tr>

<th>Filename</th>

<th>Type</th>

<th>Size <small>(bytes)</small></th>

<th>Date Modified</th>

</tr>

</thead>

<tbody>

<?php require ($_SERVER['DOCUMENT_ROOT'].'/php/displayDirectory.php5'); ?>

</tbody>

</table>

</div>

</body>

</html>

Here is my .htaccess file:

AddType application/x-httpd-php5 .php5

AddType application/x-httpd-php5 .phps

In my apache.conf I added:

LoadModule php5_module modules/mod_php55.so

However, upon restarting apache, warning displayed that its already loaded.

I have also checked if php is installed, it is and its on version 5. At this point index.html loads displayDirectory.html but php code inside it is not being processed.

Am I missing something?

网友答案:

You have syntax error:

<?php require ('$_SERVER['DOCUMENT_ROOT']./php/displayDirectory.php5'); ?>

<?php require ($_SERVER['DOCUMENT_ROOT'].'/php/displayDirectory.php5'); ?>

I've had that problem on IIS and it was caused by syntax errors. I assume you are using Apache, since you are using .htaccess:

PHP files are downloaded by browser instead of processed by local dev server (MAMP)

Apache is downloading php files instead of displaying them

.htaccess will not work if you are using IIS; you need to play around with web.config

相关阅读:
Top