main.html rep JSON amb info
diff --git a/js/utils.js b/js/utils.js
new file mode 100644
index 0000000..9f0a166
--- /dev/null
+++ b/js/utils.js
@@ -0,0 +1,23 @@
+function getUrlParameter(name) {
+ name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
+ var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
+ var results = regex.exec(location.search);
+ return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
+};
+
+function b64EncodeUnicode(str) {
+ // first we use encodeURIComponent to get percent-encoded UTF-8,
+ // then we convert the percent encodings into raw bytes which
+ // can be fed into btoa.
+ return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
+ function toSolidBytes(match, p1) {
+ return String.fromCharCode('0x' + p1);
+ }));
+}
+
+function b64DecodeUnicode(str) {
+ // Going backwards: from bytestream, to percent-encoding, to original string.
+ return decodeURIComponent(atob(str).split('').map(function(c) {
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
+ }).join(''));
+}
diff --git a/login.php b/login.php
index 5da29e7..3440136 100644
--- a/login.php
+++ b/login.php
@@ -1,6 +1,7 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
+<script src="./js/utils.js"></script>
<?php
$servername = "fdb22.awardspace.net";
$username = "3155560_users";
@@ -38,11 +39,11 @@
echo '
<script>
let infoString = JSON.stringify(db_info);
-let infoBase64 = btoa(infoString);
+let infoBase64 = b64EncodeUnicode(infoString);
window.location.href = "./main.html?info=" + infoBase64;
</script>
';
?>
</body>
-</html>
\ No newline at end of file
+</html>
diff --git a/main.html b/main.html
index 84639c1..567cfd2 100644
--- a/main.html
+++ b/main.html
@@ -4,6 +4,8 @@
<title>Pàgina de l'usuari</title>
<link rel="stylesheet" href="./css/basic.css" />
<link rel="stylesheet" href="./css/main.css" />
+
+ <script src="./js/utils.js"></script>
</head>
<body>
<div id="outter-container">
@@ -22,5 +24,10 @@
<button id="win">L'he matat</button>
<button id="lose">M'han matat</button>
</div>
+
+ <script>
+ var info = JSON.parse(b64DecodeUnicode(getUrlParameter("info")));
+ console.log(info);
+ </script>
</body>
</html>