下拉选择文件并将其包含在同一页面中 [英] Drop Down Select File And Include It into Same Page

查看:131
本文介绍了下拉选择文件并将其包含在同一页面中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试这样做,但它只回显了实际上没有选择.php文件包含在同一页面中的值。代码如下...

Tried to do this but it's only echoing the value not actually choosing the .php file to include into the same page. The code is below...

<body>
<form name="form1" method="POST" action="test.php">
<select name="select" onChange="document.form1.submit()">
 <option selected>Select an Industry</option>
 <option value="members">members</option>
 <option value="Female">Female Members</option>
</select>
</form>

<?php

$file = $_POST['select'];
echo $file;


$path_file = $_SERVER['DOCUMENT_ROOT']/$file.php;
if(file_exists($path_file))
{
  echo("The file does not exist at: $path_file");
}
else
{
  require_once($path_file);
}?>
</body>

一旦排序,我希望它会在同一页面中包含一个php文件!在更改之前还需要一个默认页面,所以会员是主页面,然后人们可以选择女性来看女性等。

Once sorted I am hoping it will include a php file into the same page! Also need a default page before changing it, so Members be the main page, then people can select Female to see just female etc.

推荐答案

更改

$path_file = $_SERVER['DOCUMENT_ROOT']/$file.php;

$path_file = $_SERVER['DOCUMENT_ROOT']."/".$file.".php";

但这对于安全性来说非常糟糕(你不能信任_POST数据)。更好地改变如下:

But this is very bad for security (you can't trust _POST data). Better change to something like:

if (isset($_POST['select']) && $_POST['select'])
{
if ($_POST['select'] == 'something')
 include 'something.php';
if ($_POST['select'] == 'somethingelse')
 include 'another.php';
} else {
  include 'default.php';
}

这篇关于下拉选择文件并将其包含在同一页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆