이것은 내 전체 코드입니다. 나에게 공유 됨. 나는이 오류가 계속 이유를 알아낼 수 없습니다
Notice: Undefined index: page in /export/home/dynamic/index.php on line 20
:
이
내 오류입니다. 그것은 처음은 아니지만, 나는 그것이 어레이라고 의심해 왔지만, 어떻게해야할지 모르겠다.내 웹 사이트에 동적 변경 페이지를 만드는 것으로 가정합니다. 나는 전역 변수를 어디서 만들었는지 오류가 있었음 $page = $_GET['page'];
나는 어떤 종류의 대답에 대해서도 개방적이며, 나는 그들 모두에게 위대한 사람들이다.
<!DOCTYPE html>
<html>
<head>
<title>Website</title>
</head>
<body>
<header>Header<br />
<nav>
<a href="index.php?page=index">INDEX</a>
<a href="index.php?page=page1">Startsida</a>
<a href="index.php?page=page2">Anteckningar</a>
<a href="index.php?page=page3">Kontakt</a>
<!-- <a href="index.php?page=faq">FAQ</a> -->
</nav></header>
<div id="content">
<?php
// Place the value from ?page=value in the URL to the variable $page.
$page = $_GET['page'];
// Create an array of the only pages allowed.
$pageArray = array(
'index',
'page1',
'page2',
'page3',
'faq'
);
// If there is no page set, include the default main page.
if (!$page) {
include('pages/index.php');
}
// Is $page in the array?
$inArray = in_array($page, $pageArray);
// If so, include it, if not, emit error.
if ($inArray == true) {
include('pages/'. $page .'.php');
}else {
echo 'Umm tisk tisk. You should not be messing with things.';
}
?>
</div>
<footer>Footer</footer>
</body>
</html>
IT SOLVED! hek2mgl 덕분에 코드가 올바르게 작동합니다.
내 문제에 대한 답변을 제출해 주셔서 감사드립니다. 나는 너희들에게 빚지고있다.
경우 단지 확인 후 통지
침묵 할 수 isset()을 사용하여 $ _GET [ 'page'] 변수의 존재를 항상 확인해야합니다. - http://de2.php.net/manual/de/function.isset.php function – Tebe