Page 1 of 2
Help with Custom Content
Posted: Sun May 31, 2009 9:22 pm
by sing2trees
Hi all,
Am looking for some advice really!
I have a site which content is only available to those who have registered and logged in. I have figured out (thanks to some people on this forum) how to create the login, pending etc.
What is the best way for to have the index.php page which will show the content if the person has logged in, or automatically redirects to mysite.com/login.php if not logged in?
Thanks!
Re: Help with Custom Content
Posted: Sun May 31, 2009 11:41 pm
by jmcgin51
AT THE VERY TOP of the template for your homepage:
{if $ccuser-->loggedin()}
content
{else}
header('Location:
http://www.mysite.com/login.php');
{/if}
Is login.php a page within CMSMS (i.e. index.php?page=login), or is it an entirely separate standalone page?
Re: Help with Custom Content
Posted: Mon Jun 01, 2009 6:33 am
by sing2trees
jmcgin51 wrote:
AT THE VERY TOP of the template for your homepage:
{if $ccuser-->loggedin()}
content
{else}
header('Location:
http://www.mysite.com/login.php');
{/if}
Is login.php a page within CMSMS (i.e. index.php?page=login), or is it an entirely separate standalone page?
Thanks for that, but am having some problems still.
The template page is as follows:
Code: Select all
{if $ccuser->loggedin() && $ccuser->memberof('team')}
<__html>
{process_pagedata}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<__html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
{* Change lang="en" to the language of your site *}
<head>
{if isset($canonical)}<link rel="canonical" href="{$canonical}" />{elseif isset($content_obj)}<link rel="canonical" href="{$content_obj->GetURL()}" />{/if}
<title>{sitename} - {title}</title>
{* The sitename is changed in Site Admin/Global settings. {title} is the name of each page *}
{metadata}
{* Don't remove this! Metadata is entered in Site Admin/Global settings. *}
{stylesheet}
{* This is how all the stylesheets attached to this template are linked to *}
</head>
</__body>
<div id="wrap">
<div id="header">
<h1><a href="#">Website Title</a></h1>
<h2>Subheader, website description H2</h2>
</div>
<div id="menu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Photos</a></li>
<li><a href="#">Links</a></li>
<li><a href="#">Forum</a></li>
<li><a href="#">Free Stuff</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">SiteMap</a></li>
</ul>
</div>
<div id="content">
{search}{content}
<div id="footer">
Designed by <a href="http://www.free-css-templates.com/">Free CSS Templates</a>, Thanks to <a href="http://www.legalhelpers.com/bankruptcy-information.html">Bankruptcy Information</a>
</div>
</div>
<__body>
</__html>
{else}
header('Location: http://www.google.com');
{/if}
However I get the following error message (whether logged in or not):
Parse error: syntax error, unexpected T_ELSE in /home/sapphire/public_html/cms/tmp/templates_c/%%76^763^76313DB0%%tpl_body%3A22.php on line 41
Any ideas what I am doing wrong?
In reply to your other question, login.php will be a page within CMSMS
Thanks again in advance!
Re: Help with Custom Content
Posted: Mon Jun 01, 2009 7:52 am
by Jeff
I think there is a limit to the number of lines that can be between the {if} and {else}.
Re: Help with Custom Content
Posted: Mon Jun 01, 2009 2:31 pm
by jmcgin51
ajprog wrote:
I think there is a limit to the number of lines that can be between the {if} and {else}.
There might be, but I don't think this is sing2trees problem. I have a template with 192 lines between {if} and {else}, and it works fine. Since sing2trees only has 54 lines, I don't think this is the issue.
I suspect it might have something to do with this line:
Code: Select all
{if isset($canonical)}<link rel="canonical" href="{$canonical}" />{elseif isset($content_obj)}<link rel="canonical" href="{$content_obj->GetURL()}" />{/if}
Try commenting it out and see what happens. In the meantime, I'll try my original suggestion and see if it works for me.
Re: Help with Custom Content
Posted: Mon Jun 01, 2009 2:45 pm
by sing2trees
jmcgin51 wrote:
ajprog wrote:
I think there is a limit to the number of lines that can be between the {if} and {else}.
There might be, but I don't think this is sing2trees problem. I have a template with 192 lines between {if} and {else}, and it works fine. Since sing2trees only has 54 lines, I don't think this is the issue.
I suspect it might have something to do with this line:
Code: Select all
{if isset($canonical)}<link rel="canonical" href="{$canonical}" />{elseif isset($content_obj)}<link rel="canonical" href="{$content_obj->GetURL()}" />{/if}
Try commenting it out and see what happens. In the meantime, I'll try my original suggestion and see if it works for me.
I tried that, but without success - I get the same error message

Did you say that you are able to do it on your site? If so, would you mind sharing the code so I can see how it works?
Re: Help with Custom Content
Posted: Mon Jun 01, 2009 2:55 pm
by jmcgin51
Ok, I forgot that the
header('Location: http://www.mysite.com/login.php'); call has to be before ANY other text sent to the browser, so it won't work in this situation. (When I tried it, it just printed "header('Location:
http://www.mysite.com/login.php');" to my browser screen.)
You could use a JavaScript redirect instead, but if the user has JS turned off, it won't work.
Duh. Just remembered that CMSMS has a built-in redirect tag.
{redirect_page page='some-page-alias'}
So your template will look like this:
{if $ccuser-->loggedin()}
content
{else}
{redirect_page page='some-page-alias'} //this is your login page
{/if}
Just tried it and it works perfectly.
Re: Help with Custom Content
Posted: Mon Jun 01, 2009 8:22 pm
by sing2trees
jmcgin51 wrote:
Ok, I forgot that the
header('Location: http://www.mysite.com/login.php'); call has to be before ANY other text sent to the browser, so it won't work in this situation. (When I tried it, it just printed "header('Location:
http://www.mysite.com/login.php');" to my browser screen.)
You could use a JavaScript redirect instead, but if the user has JS turned off, it won't work.
Duh. Just remembered that CMSMS has a built-in redirect tag.
{redirect_page page='some-page-alias'}
So your template will look like this:
{if $ccuser-->loggedin()}
content
{else}
{redirect_page page='some-page-alias'} //this is your login page
{/if}
Just tried it and it works perfectly.
I'm still getting an error message
My template is as follows:
Code: Select all
{if $ccuser->loggedin() && $ccuser->memberof('team')}
<__html>
{content}
</__html>
{else}
{redirect_page page='some-page-alias'} //this is your login page
{/if}
And the content is on the page is just 'hello' for now!
However, I get the following error message when accessing the page (when not logged in)
Fatal error: Call to a member function GetContent() on a non-object in /home/sapphire/public_html/cms/lib/misc.functions.php on line 143
Any idea what I'm doing wrong?! Sorry!!
Re: Help with Custom Content
Posted: Mon Jun 01, 2009 8:57 pm
by jmcgin51
sing2trees wrote:
My template is as follows:
Code: Select all
{if $ccuser->loggedin() && $ccuser->memberof('team')}
<__html>
{content}
</__html>
{else}
{redirect_page page='some-page-alias'} //this is your login page
{/if}
You did put your actual page alias in the {redirect_page} tag, right?
Re: Help with Custom Content
Posted: Mon Jun 01, 2009 9:05 pm
by sing2trees
Yep! Well, I put google, as I don't have the other page built yet!
Re: Help with Custom Content
Posted: Mon Jun 01, 2009 9:59 pm
by jmcgin51
you put "google" in the redirect tag? like this?
{redirect_page page='google'} or {redirect_page page='
http://www.google.com'}
unless you have a page with the alias "google", the first one will fail, and the second one is not a valid implementation of the tag.
Create a test page, put the alias in the tag, and see what happens.
Re: Help with Custom Content
Posted: Mon Jun 01, 2009 10:21 pm
by dendle
Hi All,
I have just mocked up this thread in my CMSMS Test Installation and produced the same error. As a test I put the
if then else code within the body tags of the document template rather than wrapping around the whole document. This technique works very well, first time every time.
A quick note, I use both the $ccuser-->loggedin() and the $ccuser->memberof(GROUPNAME) conditions as $ccuser seems to return true even if no-one is logged in (it seems to treat no-one logged in as an anonymous user). Please let me know if this understanding is not correct. As a note, without using $ccuser group to check the user the page will let anyone in (authenticated or otherwise).
Having said that this technique does work for me, and I am interested in others thoughts and if it helps......
I am running CMSMS 1.5.4; PHP 5.2.8; MySQL 5.0.77-community and Apache 2.2.11 running under a linux kernel 2.6.18-19.el5
IE:
Code: Select all
<__html>
</__body>
{if $ccuser-->loggedin() && $ccuser->memberof(Clients)}
....content of page if user is logged in.
{cms_module module='FrontEndUsers' form='logout}
{else}
{redirect_page page='client'}
{/if}
<__body>
</__html>
Final note, do not use this template for the login page (it will cause a recursive loop). My solution was to implement the if then else statement directly in the code of the login page itself, it looks something like this:
Code: Select all
{if $ccuser->loggedin() && $ccuser->memberof(Clients)}
{redirect_page page='client-home'}
{else}
Please use the form below to login<br />
{cms_module module='FrontEndUsers' form='login'}
{/if}
Re: Help with Custom Content
Posted: Tue Jun 02, 2009 1:59 am
by jmcgin51
dendle wrote:
Code: Select all
<__html>
</__body>
{if $ccuser-->loggedin() && $ccuser->memberof(Clients)}
....content of page if user is logged in.
{cms_module module='FrontEndUsers' form='logout}
{else}
{redirect_page page='client'}
{/if}
<__body>
</__html>
You don't need the "form='logout'" statement. If the user is logged in, the logout form is automatic. You can just do this:
Code: Select all
<__html>
</__body>
{if $ccuser-->loggedin() && $ccuser->memberof(Clients)}
....content of page if user is logged in.
{cms_module module='FrontEndUsers'}
{else}
{redirect_page page='client'}
{/if}
<__body>
</__html>
Also, this template works exactly as expected:
{if $ccuser->loggedin() && $ccuser->memberof('group')}
{process_pagedata}
{sitename} - {title}
{metadata}
{stylesheet}
{content}
{else}
{redirect_page page='whatever'}
{/if}
Re: Help with Custom Content
Posted: Tue Jun 02, 2009 2:51 am
by dendle
Hmm, thats interesting because I could not get the form to work using your method. I got the T_ELSE error the other user mentioned.
Also the logout link is not automatic (or atleast it is not for me). If I don't include the logout call then I do not get the logout links....
Any thoughts??
Re: Help with Custom Content
Posted: Tue Jun 02, 2009 6:51 am
by sing2trees
Also having a problem with that last one submiited, I get the following error message!
Parse error: syntax error, unexpected T_ELSE in /home/sapphire/public_html/cms/tmp/templates_c/%%76^763^76313DB0%%tpl_body%3A22.php on line 11