I was working my API, what you are looking at is the base case for the fetch requests, I have debugged the code, and the problem how do I get the post data variable specifically $studentnumber in the function used above and use it in the if statement function below-called login process. Both of the functions are in the same class. Heres the code :)
case "login":
if($_SESSION['user_session']->userloginstatus()) {
$studentnumber = $_POST['studentnumber'];
$password = $_POST['password'];
$response = $_SESSION['user_session']->login($studentnumber, $password);
http_response_code(206);
if ($response == true) {
$_SESSION['user_session']->loginprocess($studentnumber);
echo $_SESSION['user_session']->loginprocess();
http_response_code(202);
} else {
http_response_code(404);
}
} else {
http_response_code(401);
}
break;
Here is the class
class gaqsession {
public $loginid;
public function userloginstatus() {
if(2 > 3) {
return false;
} elseif (2 > 1) {
return true;
}
}
public function login($studentnumber, $password) {
$conn = dbconnection();
try {
$stmt = $conn->prepare("SELECT loginid, fullname, studentnumber, password, accessrights FROM login WHERE studentnumber = :studentnumber");
$stmt->bindParam(':studentnumber', $studentnumber);
$stmt->execute();
$row = $stmt->fetch();
//Php password verify
if ($password == $row['password']) {
return true;
} else {
return false;
}
}
catch (PDOException $ex) {
throw $ex;
}
}
public function log() {
$conn = dbconnection();
try {
$conn->beginTransaction();
$stmt = $conn->prepare("INSERT INTO LOG(loginid, ip, browser, activity) VALUES(1, '::1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36', 'question')");
//$stmt->bindValue(':question', $question);
//$stmt->bindValue(':catagories', $catagories);
//$stmt->bindValue(':loginid', $loginid);
$stmt->execute();
$conn->commit();
}
catch (PDOException $ex) {
$conn->rollBack();
throw $ex;
}
}
public function loginprocess($studentnumber) {
$conn = dbconnection();
$stmt = $conn->prepare("SELECT * FROM login WHERE studentnumber = :studentnumber");
$stmt->bindParam(':studentnumber', $studentnumber);
$stmt->execute();
$results = $stmt->fetchAll();
$loginid = ($results[0][0]);
$this->loginid = $loginid;
echo $this->loginid;
}
}
Aucun commentaire:
Enregistrer un commentaire