Php 如果GET变量不';不存在
在我的页面上,用户可以选择显示哪些数据。我只是使用下拉列表和获取参数来实现这一点。目前看起来是这样的: 表格:Php 如果GET变量不';不存在,php,html,Php,Html,在我的页面上,用户可以选择显示哪些数据。我只是使用下拉列表和获取参数来实现这一点。目前看起来是这样的: 表格: <form method="get" action="contents.php"> <select name="TutorialBlock"> <option value="tuts1">Block One - Starting</option> <option value="tuts2">Block Tw
<form method="get" action="contents.php">
<select name="TutorialBlock">
<option value="tuts1">Block One - Starting</option>
<option value="tuts2">Block Two</option>
<option value="tuts3">Block Three</option>
</select>
<input type="submit">
</form>
第一区-启动
第二区
第三座
根据用户选择的选项加载数据的脚本:
<?php
$var_value = $_GET['TutorialBlock'];
include '/includes/'.$var_value.'.php';
?>
这很好,PHP根据用户选择的选项包含正确的文件,问题是,如果用户没有选择选项,PHP只会抛出file not found错误,因为它正在查找一个不存在的文件。如果没有设置GET参数,有没有办法阻止PHP脚本运行
$var_value = isset($_GET['TutorialBlock']) ? $_GET['TutorialBlock'] : false;
if($var_value) {
include '/includes/'.$var_value.'.php';
} else {
// query value wasn't there
exit("TutorialBlock is required");
}
重要
您的代码很容易受到目录遍历攻击
if(isset($_GET['TutorialBlock'])) {
$var_value = $_GET['TutorialBlock'];
include '/includes/'.$var_value.'.php';
} else {
//not set
}
重要
您的代码很容易受到目录遍历攻击
if(isset($_GET['TutorialBlock'])) {
$var_value = $_GET['TutorialBlock'];
include '/includes/'.$var_value.'.php';
} else {
//not set
}
重要
您的代码很容易受到目录遍历攻击
if(isset($_GET['TutorialBlock'])) {
$var_value = $_GET['TutorialBlock'];
include '/includes/'.$var_value.'.php';
} else {
//not set
}
重要
您的代码很容易受到目录遍历攻击。您现在所做的是造成一些严重的漏洞。您永远不能信任用户输入
if(isset($_GET['TutorialBlock'])) {
$var_value = $_GET['TutorialBlock'];
include '/includes/'.$var_value.'.php';
} else {
//not set
}
您应该在白名单上运行$\u GET['TutorialBlock']
。这里有一个例子
$whitelist = array(
'page',
'blockpage',
//....etc
);
if(isset($_GET['TutorialBlock']) && !empty($_GET['TutorialBlock'])) {
// now make sure it's in the whitelist.
if(!in_array($_GET['TutorialBlock'], $whitelist)) {
die('bad page');
} else {
include '/includes/'.$_GET['TutorialBlock'].'.php';
}
} else {
// user didn't select page... do something here..
}
以上只是伪代码(示例),您仍然需要确保用户输入是vaid。您现在所做的是造成一些严重的漏洞。您永远不能信任用户输入 您应该在白名单上运行
$\u GET['TutorialBlock']
。这里有一个例子
$whitelist = array(
'page',
'blockpage',
//....etc
);
if(isset($_GET['TutorialBlock']) && !empty($_GET['TutorialBlock'])) {
// now make sure it's in the whitelist.
if(!in_array($_GET['TutorialBlock'], $whitelist)) {
die('bad page');
} else {
include '/includes/'.$_GET['TutorialBlock'].'.php';
}
} else {
// user didn't select page... do something here..
}
以上只是伪代码(示例),您仍然需要确保用户输入是vaid。您现在所做的是造成一些严重的漏洞。您永远不能信任用户输入 您应该在白名单上运行
$\u GET['TutorialBlock']
。这里有一个例子
$whitelist = array(
'page',
'blockpage',
//....etc
);
if(isset($_GET['TutorialBlock']) && !empty($_GET['TutorialBlock'])) {
// now make sure it's in the whitelist.
if(!in_array($_GET['TutorialBlock'], $whitelist)) {
die('bad page');
} else {
include '/includes/'.$_GET['TutorialBlock'].'.php';
}
} else {
// user didn't select page... do something here..
}
以上只是伪代码(示例),您仍然需要确保用户输入是vaid。您现在所做的是造成一些严重的漏洞。您永远不能信任用户输入 您应该在白名单上运行
$\u GET['TutorialBlock']
。这里有一个例子
$whitelist = array(
'page',
'blockpage',
//....etc
);
if(isset($_GET['TutorialBlock']) && !empty($_GET['TutorialBlock'])) {
// now make sure it's in the whitelist.
if(!in_array($_GET['TutorialBlock'], $whitelist)) {
die('bad page');
} else {
include '/includes/'.$_GET['TutorialBlock'].'.php';
}
} else {
// user didn't select page... do something here..
}
以上只是伪代码(示例),您仍然需要确保用户输入是vaid。是<代码>如果(!isset($_GET['TutorialBlock'])死亡('未找到参数…')代码>警告:根据用户传入的参数包含文件可能会导致严重后果。此代码很危险。@dimo414此处存在更严重的漏洞。即目录遍历/包含、LFI等。不,它不会造成XSS漏洞。他很容易受到目录遍历攻击。抱歉,你是对的,使用了错误的术语。是的<代码>如果(!isset($_GET['TutorialBlock'])死亡('未找到参数…')代码>警告:根据用户传入的参数包含文件可能会导致严重后果。此代码很危险。@dimo414此处存在更严重的漏洞。即目录遍历/包含、LFI等。不,它不会造成XSS漏洞。他很容易受到目录遍历攻击。抱歉,你是对的,使用了错误的术语。是的<代码>如果(!isset($_GET['TutorialBlock'])死亡('未找到参数…')代码>警告:根据用户传入的参数包含文件可能会导致严重后果。此代码很危险。@dimo414此处存在更严重的漏洞。即目录遍历/包含、LFI等。不,它不会造成XSS漏洞。他很容易受到目录遍历攻击。抱歉,你是对的,使用了错误的术语。是的<代码>如果(!isset($_GET['TutorialBlock'])死亡('未找到参数…')代码>警告:根据用户传入的参数包含文件可能会导致严重后果。此代码很危险。@dimo414此处存在更严重的漏洞。即目录遍历/包含、LFI等。不,它不会造成XSS漏洞。他容易受到目录遍历攻击。抱歉,你是对的,使用了错误的术语。这实际上并没有遵循概要:“如果没有GET变量,有没有办法阻止PHP脚本运行?”这实际上并没有遵循概要:“如果没有GET变量,有没有一种方法可以阻止PHP脚本运行?”这实际上并没有遵循简介:“如果没有GET变量,有没有一种方法可以阻止PHP脚本运行?”这实际上没有遵循简介:“如果没有GET变量,有没有一种方法可以阻止PHP脚本运行?”?“@user3779981绝对不是完美的。。。尝试使用
?TutorialBlock=someNonFileName
好吧,它似乎可以完成任务。我的意思是,当用户第一次进入页面时,不会设置GET变量,因此PHP会抛出错误。@user3779981绝对不是完美的。。。尝试使用?TutorialBlock=someNonFileName
好吧,它似乎可以完成任务。我的意思是,当用户第一次进入页面时,不会设置GET变量,因此PHP会抛出错误。@user3779981绝对不是完美的。。。尝试使用?TutorialBlock=someNonFileName
好吧,它似乎可以完成任务。我的意思是,当用户第一次进入页面时,不会设置GET变量,因此PHP会抛出错误。@user3779981绝对不是完美的。。。尝试使用?TutorialBlock=someNonFileName
好吧,它似乎可以完成任务。我的意思是,当用户第一次进入页面时,不会设置GET变量,因此PHP会抛出错误。谢谢提醒!我试着用这个,我把这三个变量放在了白名单中(tuts1,tuts2和tuts3),但它给了我“糟糕的一页”。我真的这样做了吗?@user3779981您如何访问$\u GET['TutorialBlock']
?(这封信上有一个打字错误。)