I have created a function in one of my Joomla PHP files. Essentially, the function checks to see if a user’s ID is found in a database. If the user’s ID is not found, then it redirects to Content-A. If the user’s ID is found in the database, then it redirects to Content B. In the code below, if $result returns true, then the user’s ID was found.
Here it is in the current working form:
else
{
// Get Current Users Joomla ID
$user =& JFactory::getUser();
// Search Database for Joomla Users ID
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('user_id');
$query->from('database_table');
$query->where('user_id = ' . $user->id);
$db->setQuery($query);
$result = $db->loadResult();
if ($result && ((JRequest::getCmd('option') != 'com_content') || (JRequest::getCmd('view') != 'article') || (JRequest::getInt('id') != 'XXX')))
{
This code says if there is a $result, and the current page loaded in the browser is not content id XXX, then execute the following function. What I need to do is also include 2 other page id’s to check. So if the user is on one of these three page IDs, then they won’t be redirected.
I’ve tried the following, but it doesn’t seem to work:
if ($result && ((JRequest::getCmd('option') != 'com_content') || (JRequest::getCmd('view') != 'article') || ((JRequest::getInt('id') != 'XXX') || (JRequest::getInt('id') != 'YYY') || (JRequest::getInt('id') != 'ZZZ'))))
{
I think I’m close, but site goes into a redirect loop when I save this code. Can someone suggest a way to fix the syntax? Thanks in advance for any help!
EDITS: There are really 4 content types that need to be handled in this workflow.
Content-A = Display if the user is logged in and their user ID is not found in a database
Content-B = Display if the user is logged in and their user ID is found in a database
Content-C = Is accessed from Content-B through a Link
Content-D = Is displayed on Content A, B & C through a light box pop up (RocketTheme’s RokBox)
Just made it a bit clean ,simple if condition will help to find the problem.
If it still doesn’t work , it’s probably the $result variable , what’s the value of it?
Use:
before the condition.