webサイトを作成しております。
headerやfooterをphpで作成し、includeして使い回したいと思っています。
index.phpより、index.htmlの方が馴染みやすいと思いますので
phpファイルで作成する事は考えていません。
また、ページタイトルなど変数で管理したい為、headerやfooterはphpで作成したいと考えています。
環境はwindows OS、MAMPを使用しています。
html
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="UTF-8"> 5 <meta name="viewport" content="width=device-width,initial-scale=1"> 6 <title></title> 7 <style> 8 header{background-color: pink;} 9 footer{background-color: gray;} 10 main{background-color: aqua;} 11 </style> 12</head> 13<body> 14 <?php include( $_SERVER['DOCUMENT_ROOT'] . 'header.php'); ?> 15 <?php include( dirname(__FILE__) . 'header.php'); ?> 16 <?php include("header.php"); ?> 17 18 <main> 19 mainの内容 20 </main> 21 22 <?php include( dirname(__FILE__) . 'footer.php'); ?> 23</body> 24</html>
PHP
1<header> 2 heaerの内容 3</header>
header、main、footerと分かりやすいように背景色をつけております。
ローカルでhttp://localhost/index.htmlにアクセスすると
mainの内容のみが表示され、
includeしている部分が全てコメントアウトされています。
includeの記述が悪いのかと思い複数で記述しましたがどれもうまくいきません。
MAMPのhttpd.confを見直していますが、
AddType application/x-httpd-php .phpを
AddType application/x-httpd-php .php .phtml .html .htmに変更するという方法も
「AddType application/x-httpd-php .php」が複数あり、どこを編集すればいいのか分かりません。
(現状、全てAddType application/x-httpd-php .php .phtml .html .htmに変更しています)
またindex.htmlと同じ階層に.htaccessを置いています。
AddType application/x-httpd-php .php .html AddType application/x-httpd-php-source .phps AddHandler application/x-httpd-php .php .html
ローカルでhttp://localhost/header.phpにアクセスするとheader.phpの内容は表示されます。
http://localhost/index.htmlでincludeがコメントアウトされてしまう原因と対処法を教えてください。
PHPファイルを直で扱う事に慣れていないので質問の仕方が悪かったらすみません。
どうぞよろしくお願いいたします。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/12/24 02:49 編集
退会済みユーザー
2018/12/24 00:55
2018/12/24 02:32
退会済みユーザー
2018/12/24 02:40
退会済みユーザー
2018/12/24 02:49
2018/12/24 12:27
退会済みユーザー
2018/12/24 13:01