Class 'update_user_info' 未在 \android_login_example\login 中找到。php
Class 'update_user_info' not found in \android_login_example\login.php
说 Class 'update_user_info' 在 \android_login_example\login 中找不到。php
这里是 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;
}
}
?>
尝试将您的 update_user.info.php 中的代码包装在一些
中
class update_user_info{
...
}
那里没有 class,只有一些功能...
我不知道为什么,但您尝试创建一个不存在的实例 class update_user_info
。这是我正在谈论的代码片段
$db = new update_user_info();
您包含一个包含结构化代码的文件,而不是 objective。只需调用函数即可使用函数 func()
或将代码重写为面向对象。
使用当前代码代替
$user = $db->VerifyUserAuthentication($email, $password);
你应该打电话给
$user = VerifyUserAuthentication($email, $password);
您实际上并没有在 update_user_info.php
中声明一个 class,只是一些函数。
类 声明如下:
class MyClass
{
// Here is a method:
public function anExampleFunction()
{
//...
}
}
您可以尝试将 class update_user_info {
放在文件的开头,将 }
放在文件的结尾,看看是否适合您;还要在每个成员函数定义前加上public
。
如果要将 update_user_info.php 用作 class
,则需要将其封装在 class 中
<?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;
}
}
}
或将 class 方法调用转换为普通函数:
$user = $db->VerifyUserAuthentication($email, $password);
至
$user = VerifyUserAuthentication($email, $password);
说 Class 'update_user_info' 在 \android_login_example\login 中找不到。php 这里是 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;
}
}
?>
尝试将您的 update_user.info.php 中的代码包装在一些
中 class update_user_info{
...
}
那里没有 class,只有一些功能...
我不知道为什么,但您尝试创建一个不存在的实例 class update_user_info
。这是我正在谈论的代码片段
$db = new update_user_info();
您包含一个包含结构化代码的文件,而不是 objective。只需调用函数即可使用函数 func()
或将代码重写为面向对象。
使用当前代码代替
$user = $db->VerifyUserAuthentication($email, $password);
你应该打电话给
$user = VerifyUserAuthentication($email, $password);
您实际上并没有在 update_user_info.php
中声明一个 class,只是一些函数。
类 声明如下:
class MyClass
{
// Here is a method:
public function anExampleFunction()
{
//...
}
}
您可以尝试将 class update_user_info {
放在文件的开头,将 }
放在文件的结尾,看看是否适合您;还要在每个成员函数定义前加上public
。
如果要将 update_user_info.php 用作 class
,则需要将其封装在 class 中<?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;
}
}
}
或将 class 方法调用转换为普通函数:
$user = $db->VerifyUserAuthentication($email, $password);
至
$user = VerifyUserAuthentication($email, $password);