Problème fonction d'enregistrement php

    Publicités

Users Who Are Viewing This Thread (Total: 0, Members: 0, Guests: 0)

Status
Not open for further replies.

#Dudule100

Membre
Apr 6, 2014
40
0
126
Bonjour,

Voila j'ai suivi un tuto pour faire un systeme d'enregistrement que j'ai modifier. Hiere, les dérniés testes que j'ai fait marchaient. J'ai fait quelques copiée collé de ce sctipte pour en faire quelques autres mais aujourd'hui sa marche plus et je ne sais pas d'ou peut venir l'erreur.

Voila mon code :
PHP:
<?php

$sessionID = $_GET ["sessionID"];
$actionget = $_GET ["action"];
$hwid = $_GET ["hwid"];
$mac = $_GET ["mac"];
$registerkey = $_GET ["registerkey"];

if (empty($sessionID)) die ("ERROR:INVALID_SESSION_ID");

$action = new action;
if ($actionget == "connect")
 $response = $action->connect($hwid, $mac);
elseif ($actionget == "register")
 $response = $action->register($hwid, $mac, $registerkey);
 else
  $response = "NO_ACTION";
 
echo rc4($sessionID, $response);

class action
{
 public $bdd;
 public function action()
 {
 try {$this->bdd = new PDO('mysql:host=localhost;dbname=name', 'user', 'pass'); }
 catch (Exception $ex) {die('ERROR:ERROR_BDD_CONNECTION');}
 }

  public function connect ($hwid, $mac)
 {
  if (!$this->hwidExist($hwid)) return ('ERROR:HWID_NOT_FOUND');
  
  $data = $this->Query("SELECT * FROM Users WHERE Hwid = ?;", array($hwid));
  if ($data['Mac'] != hash ("sha256",($mac)))
   return ('ERROR:INCORRECT_MAC');
  elseif ($data['Banned'] == 1)
   return ("ERROR:HWID_BANNED");
  else
   return ("OK") . $data="0";
 }
 
 public function register ($hwid, $mac, $registerKey)
 
 {
  $data = $this->Query("SELECT * FROM Registerkeys WHERE Registerkey = ?;", array($registerKey));
  if (empty($data['Registerkey'])) return ("ERROR:INVALID_KEY");
  if (!empty($data['Hwid'])) return ("ERROR:KEY_IS_ALREADY_USED");
  if ($this->hwidExist($hwid)) return ("ERROR:HWID_IS_ALREADY_EXIST");
 
 $this->Query("INSERT INTO Users VALUES ('', ?, ?, '0', ?);", array($hwid, hash("sha256",($mac)), getTime()));
 $this->Query("UPDATE Registerkeys SET Hwid = ? WHERE Registerkey = ?;", array($hwid, $registerKey));
 return ("OK:REGISTERED");
 } 
 
 
 private function hwidExist($hwid)
 {
  $data = $this->Query("SELECT * FROM Users WHERE Hwid = ?;", array($hwid));
  if (empty($data['Hwid']))
   return (false);
  else
   return (true);
 }
 
 private function Query($query, $args, $fetch = true)
{
 $response = $this->bdd->prepare($query);
 $response->execute($args);
 if ($fetch)
 {
  $data = $response->fetch();
  $response->closeCursor();
  return ($data);
 }
}

}

function rc4($key, $str) {
$s = array();
for ($i = 0; $i < 256; $i++) {
$s[$i] = $i;
}

$j = 0;

for ($i = 0; $i < 256; $i++) {
$j = ($j + $s[$i] + ord($key[$i % strlen($key)])) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
}

$i = 0;
$j = 0;
$res = '';

for ($y = 0; $y < strlen($str); $y++) {
$i = ($i + 1) % 256;
$j = ($j + $s[$i]) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
$res .= $str[$y] ^ chr($s[($s[$i] + $s[$j]) % 256]);
}

return $res;
}

 function getTime()
 
 {
  date_default_timezone_set('Europe/Paris');
  return date ("Y-m-d H");
 }

?>

Sa enregistre bien l'hwid dans la table Registerkeys dans la colonne Hwid. Par contre dans la table Users, sa n'enregistre ni l'Hwid ni l'adresse Mac.

Merci de l'aide que vous pourrez m'apporter.
 
Last edited:

Sapuraizu

Nouveau Marchand
Apr 3, 2016
157
2
444
Je me doute que tu ne comprends pas tout ce qu'il y a dans ce script mais l'erreur vient de :
$this->Query("INSERT INTO Users VALUES ('', ?, ?, '0', ?);", array($hwid, hash("sha256",($mac)), getTime()));

Tu as oublié les (truc, truc, truc) après Users :
$this->Query("INSERT INTO Users (truc, truc, truc, truc, truc) VALUES ('', ?, ?, '0', ?);", array($hwid, hash("sha256",($mac)), getTime()));
 
Status
Not open for further replies.