我正在寻找一种自动化我的PHP脚本的方法,它应该在一个名为SUBPAGES
的文件夹中搜索php文件,并在Dropdown
的帮助下包含php文件,就像我的例子一样每次添加新文件时重新编码。
它应该自己找到存储在SUBPAGES
文件夹中的文件,并自动包含所选文件。
任何人都可以帮助我解决它。
<html>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<div align="center">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="0" width="" height="">
<tr>
<td width="300" height="50" bgcolor="#F2F2F2">
<p align="center">
<form name="form">
<p align="center">
<select name="link" SIZE="1" onChange="window.location.href = document.form.link.options[document.form.link.selectedIndex].value;">
<option value="#" style="display:none">Choose</option>
<option value="index.php?id=page1"> Seite1 </option>
<option value="index.php?id=page2"> Seite2 </option>
</select></p>
</form>
</td>
</tr>
<tr>
<td height="20" bgcolor="#999999"> </td>
</tr>
<tr>
<td height="350">
<?php
error_reporting(0);
switch($_GET['id']) {
default:
include('Subpages/page1.php');
break; case "page2":
include('Subpages/page2.php');
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
答案 0 :(得分:1)
简单的方法。首先检查包含
之后的安全类型$page = 'Subpages/page'.settype($_GET['id'],'integer').'.php' ;
$defaultpage = 'Subpages/page1.php' ;
if (file_exists($page)) {
include($page);
}else{
include($defaultpage);
}
答案 1 :(得分:0)
使用jquery和加载函数更容易。您只需要读取所选选项的值并加载所需的文件
<div align="center">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="0" width="" height="">
<tr>
<td width="300" height="50" bgcolor="#F2F2F2">
<p align="center">
<form name="form">
<p align="center">
<select name="link" SIZE="1">
<option value="#" style="display:none">Choose</option>
<option value="page1"> Seite1 </option>
<option value="page2"> Seite2 </option>
</select>
</p>
</form>
</td>
</tr>
<tr>
<td height="20" bgcolor="#999999"> </td>
</tr>
<tr>
<td height="350" id="result"></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
$('select').on('change', function() {
$( "#result" ).load( "Subpages/" + $(this).val() + ".php" );
});
</script>
</body>