I am using Joomla 2.5 and in the head of my site I have a module with the following code:
<?php
$user =JFactory::getUser()->guest;
if ($user->guest) {
echo 'Please sign up or sign in to view this'
}
else {
echo 'Here is the content';
}
?>
What I tried but didnt work is to add a variable $member in the first if statement. If the person isnt logged in to show him the echo but also set $member to == true.
Why I want to do this? I think it would make the site load faster if I check the status of $member than to go calling the Joomla API to determine if the user is logged in or not.
The calls to determine if a visitor is a member or not in every page are about 5-7. When I use the JFactory::getUser() function (all of the code above) 5-7 times it does slow down a bit the website. Thats why I thought of creating in the first call the $member == true correct me if I am wrong in thinking this would be better in site perfomance/speed wise.
I tried this:
<?php
$user =JFactory::getUser()->guest;
if ($user->guest) {
echo 'Please sign up or sign in to view this'
$member == true;
}
else {
echo 'Here is the content';
}
?>
I have the above code in the header module. But when I later in other modules in the same page or in the article if I use a php code it doesn't recognize the status of $member and always determines the user as not logged in.
What am I doing wrong? I'm guessing its something with variables scope, I checked my PHP book but couldn't find the error. Any help appreciated.