Help with Custom Content
-
- Forum Members
- Posts: 38
- Joined: Thu May 28, 2009 9:00 pm
Help with Custom Content
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!
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
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?
{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?
-
- Forum Members
- Posts: 38
- Joined: Thu May 28, 2009 9:00 pm
Re: Help with Custom Content
Thanks for that, but am having some problems still.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?
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}
Any ideas what I am doing wrong?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
In reply to your other question, login.php will be a page within CMSMS
Thanks again in advance!
Last edited by sing2trees on Mon Jun 01, 2009 6:42 am, edited 1 time in total.
Re: Help with Custom Content
I think there is a limit to the number of lines that can be between the {if} and {else}.
Re: Help with Custom Content
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.ajprog wrote: I think there is a limit to the number of lines that can be between the {if} and {else}.
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}
-
- Forum Members
- Posts: 38
- Joined: Thu May 28, 2009 9:00 pm
Re: Help with Custom Content
I tried that, but without success - I get the same error messagejmcgin51 wrote: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.ajprog wrote: I think there is a limit to the number of lines that can be between the {if} and {else}.
I suspect it might have something to do with this line:Try commenting it out and see what happens. In the meantime, I'll try my original suggestion and see if it works for me.Code: Select all
{if isset($canonical)}<link rel="canonical" href="{$canonical}" />{elseif isset($content_obj)}<link rel="canonical" href="{$content_obj->GetURL()}" />{/if}

Re: Help with Custom Content
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.
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.
-
- Forum Members
- Posts: 38
- Joined: Thu May 28, 2009 9:00 pm
Re: Help with Custom Content
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}
However, I get the following error message when accessing the page (when not logged in)
Any idea what I'm doing wrong?! Sorry!!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
Re: Help with Custom Content
You did put your actual page alias in the {redirect_page} tag, right?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}
-
- Forum Members
- Posts: 38
- Joined: Thu May 28, 2009 9:00 pm
Re: Help with Custom Content
Yep! Well, I put google, as I don't have the other page built yet!
Re: Help with Custom Content
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.
{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
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......
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:
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......
IE: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
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>
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}
Last edited by dendle on Mon Jun 01, 2009 11:25 pm, edited 1 time in total.
-- if the facts dont fit the theory, change the theory--
Re: Help with Custom Content
You don't need the "form='logout'" statement. If the user is logged in, the logout form is automatic. You can just do this: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>
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>
{if $ccuser->loggedin() && $ccuser->memberof('group')}
{process_pagedata}
{sitename} - {title}
{metadata}
{stylesheet}
{content}
{else}
{redirect_page page='whatever'}
{/if}
Re: Help with Custom Content
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??
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??
Last edited by dendle on Tue Jun 02, 2009 4:37 am, edited 1 time in total.
-- if the facts dont fit the theory, change the theory--
-
- Forum Members
- Posts: 38
- Joined: Thu May 28, 2009 9:00 pm
Re: Help with Custom Content
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