If you want to redirect them immediately, it would take a custom snippet. Something like this:
<?php
/* CheckStatus snippet */
$loggedIn = $modx->user->hasSessionContext($modx->context->get('key'));
if ( $loggedIn) {
return '<a style="width:100px;" href="[[~14]]">member link</a>';
} else {
$url = $modx->makeUrl(31, "", "", "full");
$modx->sendRedirect($url);
}
I'm trying to create a conditional link that if a member is logged in then they would see member link instead of the sign-up link as well as a conditionall link on generic pages such as help (outside of the members area) that would generate a link back to the member area.
for testing I put [[+modx.user.id]] on the top of the page to verify the user being logged in or not
and the call to the IF snippet as:
[[!If?
&subject=`[[+modx.user.id]]`
&operator=`>`
&operand=`0`
&then=`<a style="width:100px;" href="[[~14]]">member link</a>`
&else=`<a style="width:100px;" href="[[~31]]">sign-up</a>`
]]
I've tried this cached and uncached and the only sucess is if I clear the site cache every time.
The problem I'm having is this:
If a user logs in and is taken to the clubhouse so to speak, all is well. BUT if they click on a link that leads to generic pages, eg. home page the links in the IF statement do not change and it shows the user being logged out userid=0
If I refresh the page it then shows the userid, but on logout and returning to the home page still shows a userid but links don't change and clicking on the member link results in a blank page as expected.
However, I'm still trying to figure out how to make it redirect to the home page if they are not logged in or at the very least a message that tells them they must login or sign-up to access the page. But that's another issue.
Am I missing soemthing here? Is this the right way to go about getting the result I need?
Any help would be greatly appreciated... Still a noob but learning...
-
☆ A M B ☆
- 24,524 Posts
You might do better if you used one of the snippets designed for this sort of thing.
http://modx.com/extras/package/personalize
http://modx.com/extras/package/membercheck
-
☆ A M B ☆
- 24,524 Posts
One of the virtues of great programmers - laziness. If somebody else has already done it, use their stuff