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?
You must log in to view this
Moderator: General Moderators
Code: Select all
if($logged_in)
{
//show text
} else
{
echo 'you need to login';
}Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Re: You must log in to view this
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.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?
You can filter out the hidden data for users not logged in. You could also replace it with something else..
Or..
Code: Select all
if (!$is_logged_in)
{
$display_data = preg_replace('#\[hide\].+?\[hide\]#im', '', $display_data);
}
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);
}
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
If the user isn't logged in, preg_replace it out.
Code: Select all
echo preg_replace('#\[hide\](.*?)\[/hide\]#', '', $content);