MySQL Forums
Forum List  »  PHP

Re: webserver database loginsystem
Posted by: none none
Date: August 05, 2019 09:48AM

from the "bdconnect.php" file
<?php

$DB_host = "localhost";
$DB_user = "root";
$DB_pass = "1598753";
$DB_name = "game";

$MySQLi_CON = new MySQLi($DB_host,$DB_user,$DB_pass,$DB_name);

if($MySQLi_CON->connect_errno)
{
die("ERROR : -> ".$MySQLi_CON->connect_error);
}

?>
________________________________________________

from the "gameinfo.php" file
<?php

include("dbconnect.php");

/////////////////
/////// First Function To Get User Data For Login
///////////////
if($_GET["stuff"]=="login"){

$mysqli = new mysqli($DB_host, $DB_user, $DB_pass, $DB_name);

if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}


/////// Need to Grab Username And Password
$username = $_GET["user"];
$password = $_GET["password"];

// create a prepared statement
$stmt = mysqli_prepare($mysqli, "SELECT username, password, regkey, banned FROM users WHERE username='$username'");

// check if username exists (This code is not working...!!!!)



// bind parameters
mysqli_stmt_bind_param($stmt, 's', $username);

// execute query
mysqli_stmt_execute($stmt);

// bind result variables
mysqli_stmt_bind_result($stmt, $username, $hashed_password, $regkey, $banned);

// fetch value
mysqli_stmt_fetch($stmt);


if(password_verify($password, $hashed_password)){
echo json_encode(array('result2' => 'success', 'regkey' => $regkey, 'banned' => $banned));
}else{
// incorrect password
}
mysqli_stmt_close($stmt);

$mysqli->close();
}


//////////////////////
/////// Second Function Getting The User Information
//////////////////////

if($_GET["stuff"]=="userinfo"){

$mysqli = new mysqli($DB_host, $DB_user, $DB_pass, $DB_name);

if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

//////// Gets the RegKey which is Unique To The User

$rk = $_GET["rk"];




$query = "SELECT status, username, email, banned FROM users WHERE regkey='$rk'";

if ($stmt = $mysqli->prepare($query)) {
$stmt->execute();
$stmt->bind_result($status, $username, $email, $banned,);
while ($stmt->fetch()) {
echo "{";
echo '"status": "' . $status . '",';
echo '"username": "' . $username . '",';
echo '"email": "' . $email . '",';
echo '"banned": "' . $banned . '",';
echo "}";
}


$stmt->close();
}


$mysqli->close();
}


//////////////////////
/////// Third Function Change State Of User Online/Offline
//////////////////////

if($_GET["stuff"]=="u_status"){

$conn = new mysqli($DB_host, $DB_user, $DB_pass, $DB_name);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$status = $_GET["status"];
$rk = $_GET["rk"];

$sql = "UPDATE users SET status='$status' WHERE regkey='$rk'";

if ($conn->query($sql) === TRUE) {
echo "successfully";
} else {
echo "error" . $conn->error;
}

$conn->close();
}

?>

Options: ReplyQuote


Subject
Written By
Posted
August 05, 2019 09:45AM
Re: webserver database loginsystem
August 05, 2019 09:48AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.