在\ android_login_example \ login.php中找不到类'update_user_info' 这是Login.php ...
IDK发生了什么,但我也尝试在update_user_info.php文件中的函数前删除public!它没有奏效! 我正在为Android应用创建一个登录页面和注册页面!
由于 崔西
<?php
require_once 'update_user_info.php';
$db = new update_user_info();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['email']) && isset($_POST['password'])) {
// receiving the post params
$email = $_POST['email'];
$password = $_POST['password'];
// get the user by email and password
$user = $db->VerifyUserAuthentication($email, $password);
if ($user != false) {
// use is found
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["age"] = $user["age"];
$response["user"]["gender"] = $user["gender"];
echo json_encode($response);
} else {
// user is not found with the credentials
$response["error"] = TRUE;
$response["error_msg"] = "Login credentials are wrong. Please try again!";
echo json_encode($response);
}
} else {
// required post params is missing
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters email or password is missing!";
echo json_encode($response);
}
?>
现在这是update_user_info.php ..
<?php
function StoreUserInfo($name, $email, $password, $gender, $age) {
$hash = $this->hashFunction($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$stmt = $this->conn->prepare("INSERT INTO android_php_post(name, email,
encrypted_password, salt, gender, age) VALUES(?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssss", $name, $email, $encrypted_password, $salt, $gender, $age);
$result = $stmt->execute();
$stmt->close();
// check for successful store
if ($result) {
$stmt = $this->conn->prepare("SELECT name, email, encrypted_password, salt, gender, age FROM android_php_post WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt-> bind_result($token2,$token3,$token4,$token5,$token6,$token7);
while ( $stmt-> fetch() ) {
$user["name"] = $token2;
$user["email"] = $token3;
$user["gender"] = $token6;
$user["age"] = $token7;
}
$stmt->close();
return $user;
} else {
return false;
}
}
function hashFunction($password) {
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
function VerifyUserAuthentication($email, $password) {
$stmt = $this->conn->prepare("SELECT name, email, encrypted_password, salt, gender, age FROM android_php_post WHERE email = ?");
$stmt->bind_param("s", $email);
if ($stmt->execute()) {
$stmt-> bind_result($token2,$token3,$token4,$token5,$token6,$token7);
while ( $stmt-> fetch() ) {
$user["name"] = $token2;
$user["email"] = $token3;
$user["encrypted_password"] = $token4;
$user["salt"] = $token5;
$user["gender"] = $token6;
$user["age"] = $token7;
}
$stmt->close();
// verifying user password
$salt = $token5;
$encrypted_password = $token4;
$hash = $this->CheckHashFunction($salt, $password);
// check for password equality
if ($encrypted_password == $hash) {
// user authentication details are correct
return $user;
}
} else {
return NULL;
}
}
function checkHashFunction($salt, $password) {
$hash = base64_encode(sha1($password . $salt, true) . $salt);
return $hash;
}
function CheckExistingUser($email) {
$stmt = $this->conn->prepare("SELECT email from android_php_post WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
// user existed
$stmt->close();
return true;
} else {
// user not existed
$stmt->close();
return false;
}
}
?>
答案 0 :(得分:0)
尝试将update_user.info.php中的代码包装在某些
中 class update_user_info{
...
}
你没有上课,只有一些功能......
答案 1 :(得分:0)
我不知道为什么,但您尝试创建一个不存在的类update_user_info
的实例。这是我正在谈论的代码的片段
$db = new update_user_info();
您包含带有结构化代码的文件,而不是客观的。使用函数只需调用它func()
或将代码重写为面向对象。
使用当前代码
$user = $db->VerifyUserAuthentication($email, $password);
你应该致电
$user = VerifyUserAuthentication($email, $password);
答案 2 :(得分:0)
你实际上并没有在update_user_info.php
中声明一个类,只是一些函数。
类声明如下:
class MyClass
{
// Here is a method:
public function anExampleFunction()
{
//...
}
}
您可以尝试将class update_user_info {
放在文件的开头,然后}
放在最后,看看它是否适合您;还将public
放在每个成员函数定义的前面。
答案 3 :(得分:0)
如果要将它用作类,则需要在类中封装update_user_info.php
<?php
class update_user_info {
function StoreUserInfo($name, $email, $password, $gender, $age) {
$hash = $this->hashFunction($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$stmt = $this->conn->prepare("INSERT INTO android_php_post(name, email,
encrypted_password, salt, gender, age) VALUES(?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssss", $name, $email, $encrypted_password, $salt, $gender, $age);
$result = $stmt->execute();
$stmt->close();
// check for successful store
if ($result) {
$stmt = $this->conn->prepare("SELECT name, email, encrypted_password, salt, gender, age FROM android_php_post WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt-> bind_result($token2,$token3,$token4,$token5,$token6,$token7);
while ( $stmt-> fetch() ) {
$user["name"] = $token2;
$user["email"] = $token3;
$user["gender"] = $token6;
$user["age"] = $token7;
}
$stmt->close();
return $user;
} else {
return false;
}
}
function hashFunction($password) {
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
function VerifyUserAuthentication($email, $password) {
$stmt = $this->conn->prepare("SELECT name, email, encrypted_password, salt, gender, age FROM android_php_post WHERE email = ?");
$stmt->bind_param("s", $email);
if ($stmt->execute()) {
$stmt-> bind_result($token2,$token3,$token4,$token5,$token6,$token7);
while ( $stmt-> fetch() ) {
$user["name"] = $token2;
$user["email"] = $token3;
$user["encrypted_password"] = $token4;
$user["salt"] = $token5;
$user["gender"] = $token6;
$user["age"] = $token7;
}
$stmt->close();
// verifying user password
$salt = $token5;
$encrypted_password = $token4;
$hash = $this->CheckHashFunction($salt, $password);
// check for password equality
if ($encrypted_password == $hash) {
// user authentication details are correct
return $user;
}
} else {
return NULL;
}
}
function checkHashFunction($salt, $password) {
$hash = base64_encode(sha1($password . $salt, true) . $salt);
return $hash;
}
function CheckExistingUser($email) {
$stmt = $this->conn->prepare("SELECT email from android_php_post WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
// user existed
$stmt->close();
return true;
} else {
// user not existed
$stmt->close();
return false;
}
}
}
或者将类方法调用转换为普通函数:
$user = $db->VerifyUserAuthentication($email, $password);
到
$user = VerifyUserAuthentication($email, $password);