Community discussions

MikroTik App
 
tiftok
newbie
Topic Author
Posts: 49
Joined: Thu Apr 07, 2016 1:40 pm

this code will be make cookies in web browser

Fri Nov 10, 2023 6:50 pm

this videos how to edit login page :
https://www.youtube.com/watch?v=5XddDvUEU7o
How to add cookies in MikroTik Hotspot page
this code will be make cookies in web browser
if the phone have random mac or if you need save cookies only in client device
before head tage in login page
	<script type="text/javascript">

 window.addEventListener('load', function() {
  // Function to check if a cookie exists
  function checkCookie(cookieName) {
    var cookies = document.cookie.split("; ");
    for (var i = 0; i < cookies.length; i++) {
      var cookie = cookies[i].split("=");
      if (cookie[0] === cookieName) {
        return cookie[1];
      }
    }
    return null;
  }

  // Get the values from the cookies
  var username = checkCookie("usernameX");
  var password = checkCookie("passwordX");

  // Set textbox values if cookies are valid
  if (username !== null && password !== null) {
    document.login.username.value = username;
    document.login.password.value = password;
  }
});
 function setCookie(cookieName, cookieValue, expirationDays) {
  var d = new Date();
  d.setTime(d.getTime() + (expirationDays * 24 * 60 * 60 * 1000));
  var expires = "expires=" + d.toUTCString();
  document.cookie = cookieName + "=" + cookieValue + ";" + expires + ";path=/";
}

</script>
in dologin function
setCookie("usernameX", document.login.username.value, 2);
		setCookie("passwordX", document.login.password.value, 2);
		

Who is online

Users browsing this forum: itess and 2 guests