I am using the following to get the users username: Code: $isloggedin=Am_Lite::getInstance()->isLoggedIn(); $username=Am_Lite::getInstance()->getUsername(); But when a user is not logged in i want to set them a default username of : nulluser how can i do this?
You can use this code: PHP: $username = Am_Lite::getInstance()->getUsername() ?: 'nulluser'; Best Regards.
Thanks Caesar, but how can i set the username as 'nulluser' only if the username is not already set? (user is not logged in) i am thinking maybe do an if statement to check if username is above 0 characters, and if not then set username as nulluser. is their a better way and if so could you provide an example?
Please test my code. It works exactly as you need. If user is logged in then variable $username will have his username and otherwise string nulluser.
You are welcome! It is shortcut of PHP ternary operator: https://www.php.net/manual/en/langu...son.php#language.operators.comparison.ternary Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise. Am_Lite::getInstance()->getUsername() call return: username if user is logged in false otherwise