-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.php
More file actions
75 lines (66 loc) · 2.05 KB
/
service.php
File metadata and controls
75 lines (66 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
ini_set("soap.wsdl_cache_enabled", "0");
include("./helpers/database.php");
if (isset($_GET['wsdl']) || $_SERVER['REQUEST_METHOD'] === 'GET') {
header("Content-Type: text/xml");
readfile('test.wsdl');
exit;
}
class RequestStructure
{
public $username;
public $password;
public $type;
}
function authenticateUser($mysqli, $username, $password)
{
try {
if ($stmt = $mysqli->prepare("SELECT accountStatus FROM users WHERE username = ? AND userPassword = ?")) {
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 1) {
$row = $result->fetch_assoc();
return $row['accountStatus'] == 1;
}
}
} catch (Exception $ex) {
return false;
}
return false;
}
function getBookList($userInput)
{
global $mysqli;
if (!authenticateUser($mysqli, $userInput->username, $userInput->password)) {
return ['error' => "Kullanici adi veya parola hatali."];
}
try {
$query = "SELECT name,id FROM books WHERE tur = ? ORDER BY id DESC";
if ($stmt = $mysqli->prepare($query)) {
$stmt->bind_param("s", $userInput->type);
$stmt->execute();
$result = $stmt->get_result();
$xml = new SimpleXMLElement('<kitapListesi/>');
while ($row = $result->fetch_assoc()) {
$kitapXml = $xml->addChild('kitap');
$kitapXml->addChild('kitapIsim', htmlspecialchars($row['name']));
$kitapXml->addChild('kitapId', htmlspecialchars($row['id']));
}
return (object) [
'result' => $xml->asXML()
];
}
} catch (Exception $ex) {
return (object) [
'error' => "Islem sirasinda bir hata olustu."
];
}
}
$server = new SoapServer("test.wsdl", [
'classmap' => [
'RequestStructure' => 'RequestStructure',
]
]);
$server->addFunction('getBookList');
$server->handle();