53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
|
<?php
|
||
|
$config = parse_ini_file(__DIR__ . '/../config/flashii.ini');
|
||
|
|
||
|
header('Content-Type: text/plain; charset=us-ascii');
|
||
|
|
||
|
$name = (string)filter_input(INPUT_GET, 'name', FILTER_SANITIZE_STRING);
|
||
|
if(empty($name))
|
||
|
die('-1');
|
||
|
|
||
|
$config = parse_ini_file($config['msz-config-path'], true, INI_SCANNER_TYPED);
|
||
|
if(empty($config))
|
||
|
die('-2');
|
||
|
|
||
|
$info = $config['Database'];
|
||
|
if(empty($config))
|
||
|
die('-2');
|
||
|
|
||
|
$dsn = 'mysql:';
|
||
|
|
||
|
if ($info['unix_socket'] ?? false) {
|
||
|
$dsn .= 'unix_socket=' . $info['unix_socket'] . ';';
|
||
|
} else {
|
||
|
$dsn .= 'host=' . ($info['host'] ?? '127.0.0.1') . ';';
|
||
|
$dsn .= 'port=' . intval($info['port'] ?? 3306) . ';';
|
||
|
}
|
||
|
|
||
|
$dsn .= 'charset=' . ($info['charset'] ?? 'utf8mb4') . ';';
|
||
|
$dsn .= 'dbname=' . ($info['database'] ?? 'misuzu') . ';';
|
||
|
|
||
|
try {
|
||
|
$flashii = new PDO($dsn, ($info['username'] ?? null), ($info['password'] ?? null), [
|
||
|
PDO::ATTR_CASE => PDO::CASE_NATURAL,
|
||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||
|
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
|
||
|
PDO::ATTR_STRINGIFY_FETCHES => false,
|
||
|
PDO::ATTR_EMULATE_PREPARES => false,
|
||
|
PDO::MYSQL_ATTR_INIT_COMMAND => "
|
||
|
SET SESSION
|
||
|
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION',
|
||
|
time_zone = '+00:00';
|
||
|
"
|
||
|
]);
|
||
|
} catch(PDOException $ex) {
|
||
|
die('-3');
|
||
|
}
|
||
|
|
||
|
$userId = $flashii->prepare('SELECT `user_id` FROM `msz_users` WHERE LOWER(`username`) = :username OR LOWER(`email`) = :email');
|
||
|
$userId->bindValue('username', $name);
|
||
|
$userId->bindValue('email', $name);
|
||
|
$userId->execute();
|
||
|
|
||
|
echo (int)$userId->fetchColumn();
|