【发布时间】:2011-09-13 14:29:04
【问题描述】:
我正在创建一个非常基本的 iPhone 模拟器,我想做的只是将它放在一个位置,然后我们拥有并想要放置它的任何站点,我们只需使用以下命令调用它:http://www.example.com/iphone-test.php?url=http://www.example.com/mobile/
有什么我需要注意的可能不安全的地方吗?不涉及数据库或其他任何东西,但以防万一有人想乱七八糟并在 URL 中放一些东西,我可以做些什么来帮助使它更安全一点?
这是我的代码:
<?php
if(isset($_GET['url'])) {
$url = $_GET['url'];
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>iPhone Test</title>
<style type="text/css">
#iphone {
background:url(iPhone.png) no-repeat;
width:368px; height:706px;
position:relative;
overflow:hidden;
}
#iphone iframe {
position:absolute;
left:30px;
top:143px;
border:0;overflow:hidden;
}
</style>
</head>
<body>
<div id="iphone">
<iframe src="<?=$url;?>" width="307" height="443"><p>Your Browser does not support iFrames.</p></iframe>
</div>
</body>
</html>
<?php
}
?>
编辑:感谢您的所有帮助。我做了一些研究,这是我目前所拥有的:
<?php
include_once 'filter.php';
$filter = new InputFilter();
if(isset($_GET['url'])) {
if (filter_var($_GET['url'], FILTER_VALIDATE_URL)) {
$url = $filter->process($_GET['url']);
?>
来源:http://oozman.com/php-tutorials/avoid-cross-site-scripting-attacks-in-php/
班级:http://www.phpclasses.org/browse/file/8941.html
你怎么看?
【问题讨论】:
-
首先,请确保 URL 不以
javascript:... 开头... 并确保在将 URL 传递到脚本之前在客户端对 URL 进行了 URL 编码。 -
不要相信客户端对数据进行编码以使服务器可以安全地插入到文档中。
标签: php security variables get