【发布时间】:2015-10-19 19:48:33
【问题描述】:
我已经创建了一个文件目录系统。这里有一个创建目录的功能,我想阻止用户在 ../ 中创建目录,即一个文件夹,因此我创建了一个带有 strpos 的 if 语句来搜索它。代码如下:
<div class="FormElement">
<form method="post">
<input type="text" name="newFolder" id="newFolder" class="newFolder"/>
<input type="submit" value="Create">
</form>
<?php
$uniqueUserPath = $_SESSION['userPath'];
$folderName = $_POST['newFolder'];
$makeFolder = $uniqueUserPath . "/" . $folderName;
// mkdir($uniqueUserPath . "/" . $folderName);
if (strpos($folderName, "../") == true) {
echo 'there is a slash.';
} else {
mkdir($uniqueUserPath . "/" . $folderName);
echo 'there isnt a slash';
}
?>
</div>
如果你在那里输入“../”,它仍然会回显,没有斜线,更重要的是,它会开始在用户文件夹之外的文件夹中创建目录。
任何帮助将不胜感激 亲切的问候,
【问题讨论】:
-
利用
realpath -
你能给我一个例子吗,因为我在阅读 php 文档后不知道如何使用它:)
-
=== true因为0 == true但你想要!== false。 -
strpos不会返回布尔值,除非它找不到针。所以!== false就是你想要的。