Page 1 of 1
You must log in to view this
Posted: Sat Jul 14, 2007 12:48 pm
by ankhmor
I'm about to start building a site.
I want to have a function on my site that you need to log in to view text that is enclosed in [hide][/hide].
How do I do that?
Or maybe I just enclose the text in [hide][hide] and then use explode?
Posted: Sat Jul 14, 2007 1:43 pm
by s.dot
Code: Select all
if($logged_in)
{
//show text
} else
{
echo 'you need to login';
}

Re: You must log in to view this
Posted: Sat Jul 14, 2007 2:00 pm
by califdon
ankhmor wrote:I'm about to start building a site.
I want to have a function on my site that you need to log in to view text that is enclosed in [hide][/hide].
How do I do that?
Or maybe I just enclose the text in [hide][hide] and then use explode?
I can't make any sense out of your question. It sounds like you're asking how to authenticate a web page; if so, that's a question that requires a
much longer answer than can be given in a forum.
Posted: Sat Jul 14, 2007 2:11 pm
by Benjamin
You can filter out the hidden data for users not logged in. You could also replace it with something else..
Code: Select all
if (!$is_logged_in)
{
$display_data = preg_replace('#\[hide\].+?\[hide\]#im', '', $display_data);
}
Or..
Code: Select all
if (!$is_logged_in)
{
$display_data = preg_replace('#\[hide\].+?\[hide\]#im', '<strong>You must logged in to view this content</strong>', $display_data);
}
Posted: Sat Jul 14, 2007 2:13 pm
by superdezign
If the user isn't logged in, preg_replace it out.
Code: Select all
echo preg_replace('#\[hide\](.*?)\[/hide\]#', '', $content);
Posted: Sat Jul 14, 2007 10:02 pm
by ankhmor
Oh. Thanks the preg_replace function is what I'm looking for. And to think of it I use preg_split and preg_match in everyday of my life.