我有一个 nginx 重写规则,它将 img src 属性重定向到 php 页面。在此 php 页面中,我尝试发出 GET 请求,成功后会向同一页面发出 POST 请求,将从 GET 请求返回的数据作为数据发送。为什么php脚本中$_POST数据为空?如果我硬编码$name = "http://path/to/my/img.png"
在 php 脚本中图像正确呈现。
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
var_dump($_REQUEST);
//if(isset($_POST['val'])) {
// open the file in a binary mode
$name = $_POST['val']; // ALWAYS EMPTY
$fp = fopen($name, 'rb');
// send the right headers
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));
// dump the picture and stop the script
//echo fpassthru($fp);
header("Location: $name");
exit;
//}
?>
<html>
<head>
<script type='text/javascript' src='/steal/steal.js'></script>
<script type="text/javascript" src="/plugins/jquery/json2.js"></script>
<script type="text/javascript">
steal('jquery/dom/fixture').then(function(){
$.fixture("GET /event/{code}", function(original, settings, headers){
return [200, "success", { "img_url":"http://path/to/my/img.png" }, {} ]
})
var strObj = <?php echo json_encode($_REQUEST); ?>;
var str = strObj.q;
var eventCode = str.split('/')[1];
$.ajax({
url: "/event/"+eventCode,
success: function(data) {
var imgUrl = data.img_url
$.ajax({
type: 'POST',
contentType: 'json',
data: {val:imgUrl},
success: function(data){
console.log(data);
},
error: function(jqXHR, textStatus, errorThrown){
console.log(textStatus);
}
});
}
});
});
</script>
</head>
<body>
</body>
</html>
好吧,你已经超出了可能的范围。
当用户在电子邮件中点击该图像时,系统会向您的服务器发送请求该图像的请求。这些 javascript 都不会返回给用户,因为<img>
标签需要图像,而不是 html 文档。您可以通过类似的方式将内容添加到传出请求中
<img src="http://yourwebsite.com/tracker.php?val=someimage.png">
你的脚本将能够得到val
out of $_GET
但您将无法从电子邮件内对此图像发出 POST 请求。
所有这些$_REQUEST
你在顶部得到的数据?您可以从那里获取所有电子邮件跟踪数据。你能从那里得到的一切$_GET
这就是你所得到的一切。
之后,您需要向他们返回图像。这就是你如何做到这一点。
$val = $_GET['val']; // assuming val contains an image
header('Content-Type: image/png');
readfile('/path/to/your/images/'. $val);
请注意,您需要进行健全性检查$val
以确保它只包含您希望能够看到的图像。潜在的恶意用户可能会看到这一点并输入类似的内容tracker.php?val=/etc/passwd
或类似的东西,然后 PHP 会尝试读取你的密码文件。确保图像存在并且甚至可以读取可以使用is_readable() http://www.php.net/manual/en/function.is-readable.php功能。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)