Capturing information to a log file when the user clicks the submit button

The solution to this question is most likely related to data usage, but unfortunately Squarespace does not work well with many databases like mySQL.

My question is if there is any way or code I can implement without setting up the database to capture some information (username, IP address, location, timestamp) when a user on the site clicks the submit button and feed it to the log file? I'm sure there should be, and I apologize for not having any code related to my question, I'm still researching solutions. I can provide jQuery code for the button:

<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>

      

+3


source to share


1 answer


To post data with AJAX using jQuery

$("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;
});

      

Then execute $_POST

in myform.php

and write data beforesome.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);

      

With respect to location - there may be problems understanding this article.

0


source







All Articles