【发布时间】:2016-10-04 03:18:12
【问题描述】:
我只是想制作一个简单的 PHP 程序,让我可以快速生成我的页面。
我是 PHP 的新手。我不知道自己在做什么。
/index.php
<?php
include "/base/startup.php";
echo "Test";
startPage("Home");
?>
我收到 500 服务器错误。请告诉我我做错了什么。谢谢。
/base/startup.php
$HOME = "/";
$SCRIPT = <<<EOD
EOD;
$IMPORTS = array(
"/scripts/script.js"
);
$STYLES = array(
"/styles/style.css"
);
function prnt($string) {
echo $string;
}
function map($func, $arr) {
foreach($arr as $i) {
call_user_func($func, $i);
}
}
function linkScript($script) {
prnt("<script src='$script'></script>");
}
function linkStyle($style) {
prnt("<link rel='stylesheet' href='$style'/>");
}
function startPage($title, $script="", $imports=array(), $styles=array()) {
$pre_tags = array(
"<html>",
"<head>"
);
$post_tags = array(
"</head>",
"<body>"
);
map(prnt, $pre_tags);
prnt("<title>$title</title>");
map(linkScript, $IMPORTS);
map(linkScript, $imports);
map(linkStyle, $STYLES);
map(linkStyle, $styles);
map(prnt, $post_tags);
}
function genNav() {
$nav_links = array(
"Home"=>$HOME,
"Walkthroughs"=>$HOME . "/walkthroughs/",
"Dex"=>$HOME . "dex.php"
);
prnt("<div class='nav'>");
foreach ($nav_links as $key => $value) {
prnt("<a class='link' href='" . $value . "'/>" . $key . "</a>");
}
}
function endPage() {
$endTags = array(
"</body>",
"</html>"
);
}
?>
这是错误:
Warning: include(/base/startup.php): failed to open stream: No such file or directory in /var/www/html/index.php on line 2
Warning: include(): Failed opening '/base/startup.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/index.php on line 2
Test
Fatal error: Uncaught Error: Call to undefined function startPage() in /var/www/html/index.php:4 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 4
【问题讨论】:
-
我没有发现您的代码有任何语法错误。所以它应该是一些运行时错误。请通过在代码顶部添加
ini_set("display_errors", 1)来启用display_errors。 -
另请参阅此答案以了解如何启用错误:stackoverflow.com/questions/5438060/… 请告诉我们您遇到的错误是什么。
-
尝试删除
include中的/。将其更改为:include "base/startup.php"; -
@script8man 试试
/etc/php.ini或/etc/php/php.ini。如果还是找不到:创建一个空的 php 文件(例如名为info.php)并在其中写入<?php phpinfo();。 -
这可能是@PraveenKumar 所说的。您试图包含错误的文件(您的系统上可能没有
/base?)。
标签: php