function authUploaderToken() { global $dbr, $cfg_expire_uploader; $user = authCheck(); if ($user === false) { return false; } $stm = $dbr->prepare('SELECT * FROM uploader WHERE charId = :charId;'); $stm->bindValue(':charId', $user[0]); if (!$stm->execute()) { die('sql error'); } $row = $stm->fetch(); if ($row) { return $row['sessionId']; } require 'PassHash.class.php'; $ph = new PassHash(); $token = $ph->gen_salt(32); $stm = $dbr->prepare('INSERT INTO uploader (charId, charName, sessionId, createdAt) VALUES (:charId, :charName, :sessionId, :createdAt);'); $stm->bindValue(':charId', $user[0]); $stm->bindValue(':charName', $user[1]); $stm->bindValue(':sessionId', $token); $stm->bindValue(':createdAt', time()); if (!$stm->execute()) { die('sql error'); } return $token; }