[英]Capture information to log file when user clicks 'submit' button
这个问题的解决方案很可能涉及数据库,但不幸的是,Squarespace不能很好地与许多数据库一起使用,例如mySQL。
我的问题是,当网站上的用户点击“提交”按钮并将其传输到a时,如果有任何方法或代码可以实现,而无需设置数据库来捕获一些信息(用户名,IP地址,位置,时间戳)日志文件? 我确信必须有,我为没有准备好与我的问题相关的任何代码而道歉,我仍在研究解决方案。 我可以为按钮提供jQuery代码:
<body>
<div id="popup" align="right">
<object type="text/html" id="terms" data="/popup-form" width="60%" height="90%" style="overflow: auto">
</object><br>
<form>
<input id="cancel" type="button" value="Cancel" onClick="history.go(-1);return true;"/>
<input id="submit" type="submit" value="I Agree" />
</form>
</div>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script>
$("form").on("submit", function(e){
e.preventDefault();
$("#popup, #overlay").hide();
$.cookie("popup", "displayed", { expires: 7 });
});
var hasSeenpopup = $.cookie('popup');
if(!hasSeenpopup){
$("<div>",{ id : "overlay" }).insertBefore("#popup");
$("#popup").show();
}
</script>
</body>
使用jQuery使用AJAX发送数据
$("form").on("submit", function(e){
//your previous code
$.ajax({
type: "POST",
url: "myform.php",
data: {'form': $("form").serialize()},
success: function(message) {
//do whatever
}
});
return false;
});
然后在myform.php
处理$_POST
并将数据写入 some.log
$string = '';
$date = date('Y-m-d H:i:s');
$ip = '';
if (!isset($_SERVER['SERVER_ADDR'];))
$ip = $_SERVER['SERVER_ADDR'];
$string = $date.' : '.$ip.PHP_EOL;
file_put_contents('some.log', $string, FILE_APPEND);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.