Support
Quality
Security
License
Reuse
kandi has reviewed wechat-mp-sdk and discovered the below as its top functions. This is intended to give you an instant insight into wechat-mp-sdk implemented functionality, and help decide if they suit your requirements.
Get all kandi verified functions for this library.
Get all kandi verified functions for this library.
wechat management platform java sdk
QUESTION
Php if function was called outside of class
Asked 2022-Apr-09 at 18:18I'm making SDK for a web platform, there is a client class which requires cookie to authorize and there is a function that gets auth token from cookie. So my question is: how to check if function was called outside of class. I need this because i want to protect this function with password and make it so if class called it, it would work without a password. Here is my code:
public function gettoken(?string password = ""): string{
//check if it's called inside of class
if (fromClass() == true){
//code that gets token
}
//if it's called outside of class
if ($password == $this->password){
//code that gets token
}
return "Incorrect password";
}
ANSWER
Answered 2022-Apr-09 at 18:18This sound very much like a bad idea.
Why not make two functions: One public that requires a password and one private that doesn't. The public function can, of course, call the private function after the password has been verified.
Something like this:
public function getTokenUsingPassword($password)
{
if ($password == $this->password) {
return $this->getToken();
}
return false;
}
private function getToken()
{
return //code that gets token
}
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit
Open Weaver – Develop Applications Faster with Open Source