All POST. Introduced the 'user' cookie
diff --git a/ajax/checkrequests.php b/ajax/userinfo.php
similarity index 88%
rename from ajax/checkrequests.php
rename to ajax/userinfo.php
index fb6e9a6..686287d 100644
--- a/ajax/checkrequests.php
+++ b/ajax/userinfo.php
@@ -1,6 +1,6 @@
<?php
require '../php/utils.php';
- $user = get_users($_GET['id']);
+ $user = get_users($_POST['id']);
echo '{ ';
$first = true;
diff --git a/index.php b/index.php
index 92c6850..d5ff246 100644
--- a/index.php
+++ b/index.php
@@ -12,7 +12,7 @@
<div id="inner-container">
<h1>Selecciona el teu nom</h1>
<h3>Per entrar al joc de la Pastanaga Assessina</h3>
- <form action="main.php" method="GET">
+ <form action="./php/login.php" method="POST">
<select name="user" id="list">
</select>
diff --git a/js/utils.js b/js/utils.js
index 5f22129..4795075 100644
--- a/js/utils.js
+++ b/js/utils.js
@@ -8,12 +8,13 @@
function send_request(user, msg) {
$.ajax({
'url': './php/request.php',
- 'type': 'GET',
- 'contentType': 'application/json; charset=utf-8',
+ 'type': 'POST',
+ // 'contentType': 'application/json; charset=utf-8',
'data': { 'user_id': user.id,
'user_quimata': user.quimata,
'msg': msg
- },
+ },
+ dataType:'text',
'success': function(data) {
$.notify('Resposta guardada', 'success');
console.log(data);
@@ -43,15 +44,15 @@
function update_info(user) {
$.ajax({
- url: "./ajax/checkrequests.php",
+ url: "./ajax/userinfo.php",
data: { id: user.id },
- type: 'GET',
+ type: 'POST',
success: function(response, status, xhr) {
let info = JSON.parse(response);
// Check if user is dead
if (!user.mort) user.mort = check_requests(info, user);
- else location.reload();
+ else window.location.href= "./index.php";
// Check if there has been a change of victim
if (info.quimata != user.quimata) {
diff --git a/main.php b/main.php
index a19dbd3..aa6d102 100644
--- a/main.php
+++ b/main.php
@@ -1,3 +1,9 @@
+<?php
+ if (!isset($_COOKIE['user'])) {
+ header("Location: ./main.php");
+ die();
+ }
+?>
<html>
<head>
<meta charset="UTF-8">
@@ -13,7 +19,10 @@
<script src="./js/animations.js"></script>
<?php
- require './php/login.php';
+ require './php/utils.php';
+ $user = get_users($_COOKIE['user']);
+ $victim = get_users($user->quimata);
+ if ($user->mort) die('Puto mort de merda');
?>
<script>
diff --git a/php/login.php b/php/login.php
index 5ab5cdb..851f412 100644
--- a/php/login.php
+++ b/php/login.php
@@ -1,7 +1,15 @@
<?php
require 'utils.php';
- $user = get_users($_GET['user']);
- $victim = get_users($user->quimata);
- if ($user->mort) die("Puto mort de merda");
+ // Set the 'user' POST and COOKIE variable
+ if (isset($_POST['user'])) {
+ setcookie('user', $_POST['user'], time() + (86400 * 10), "/");
+ } else if (isset($_COOKIE['user']) && !isset($_POST['user'])) {
+ $_POST['user'] = $_COOKIE['user'];
+ } else if (!isset($_COOKIE['user']) && !isset($_POST['user'])) {
+ header("Location: ./index.php");
+ die();
+ }
+
+ header("Location: ../main.php");
?>
diff --git a/php/request.php b/php/request.php
index 7ef87ab..f010b36 100644
--- a/php/request.php
+++ b/php/request.php
@@ -1,25 +1,26 @@
<?php
// Define MySQL login variables
- $servername = "localhost"; // "fdb22.awardspace.net";
- $username = "root"; // "3155560_users";
- $password = ""; // "btechnoro@fox4news.info";
+ $servername = "localhost"; // "andreuhuguet78654.ipagemysql.com";
+ $username = "root"; // "andreu";
+ $password = ""; // "1234";
+ $dbname = "pastanaga"; // "fme_2019";
// Create connection
- $conn = new mysqli($servername, $username, $password, "pastanaga");
+ $conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
$conn->set_charset("utf8");
// Do the query
$queries = [""];
- $victimid = "ANY (SELECT quimata FROM users WHERE id=".(int)$_GET['user_id'].")";
+ $victimid = "ANY (SELECT quimata FROM users WHERE id=".(int)$_POST['user_id'].")";
- if ($_GET['msg'] == "REQ KILL") $queries = ["UPDATE users SET requested=1 WHERE id=".$victimid]; // request kill
- if ($_GET['msg'] == "REQ DEAD") $queries = ["UPDATE users SET requested=2 WHERE quimata=".(int)$_GET['user_id']]; // request dead
- if ($_GET['msg'] == "DENY REQ") $queries = ["UPDATE users SET requested=0 WHERE id=".(int)$_GET['user_id']]; // deny request
- if ($_GET['msg'] == "CONF DEAD") {
- $queries = ["UPDATE users SET requested=0, quimata=".(int)$_GET['user_quimata']." WHERE quimata=".(int)$_GET['user_id'], // assign new victim to killer
- "UPDATE users SET quimata=0, mort=1 WHERE id=".(int)$_GET['user_id']]; // confirm victim dead/killed
+ if ($_POST['msg'] == "REQ KILL") $queries = ["UPDATE users SET requested=1 WHERE id=".$victimid]; // request kill
+ if ($_POST['msg'] == "REQ DEAD") $queries = ["UPDATE users SET requested=2 WHERE quimata=".(int)$_POST['user_id']]; // request dead
+ if ($_POST['msg'] == "DENY REQ") $queries = ["UPDATE users SET requested=0 WHERE id=".(int)$_POST['user_id']]; // deny request
+ if ($_POST['msg'] == "CONF DEAD") {
+ $queries = ["UPDATE users SET requested=0, quimata=".(int)$_POST['user_quimata']." WHERE quimata=".(int)$_POST['user_id'], // assign new victim to killer
+ "UPDATE users SET quimata=0, mort=1 WHERE id=".(int)$_POST['user_id']]; // confirm victim dead/killed
}
// Fetch the information of the user
foreach ($queries as $query) {
diff --git a/php/utils.php b/php/utils.php
index c6147fd..fd8d731 100644
--- a/php/utils.php
+++ b/php/utils.php
@@ -16,12 +16,13 @@
$users = [];
// Define MySQL login variables
- $servername = "localhost"; // "fdb22.awardspace.net";
- $username = "root"; // "3155560_users";
- $password = ""; // "btechnoro@fox4news.info";
+ $servername = "localhost"; // "andreuhuguet78654.ipagemysql.com";
+ $username = "root"; // "andreu";
+ $password = ""; // "1234";
+ $dbname = "pastanaga"; // "fme_2019";
// Create connection
- $conn = new mysqli($servername, $username, $password, "pastanaga");
+ $conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
$conn->set_charset("utf8");