Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-11-01 12:54:05

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Restrict access to webpages?

My client wants visitors to agree to a disclaimer (check box/submit) before viewing some web pages, is there a plugin that will help me or can anyone suggest an approach?

An example: 20 page site, 5 can not be viewed without agreeing to disclaimer, but if the disclaimer is agreed to when viewing page 3 for example then the disclaimer doesn’t need to be re shown when visiting the other pages.

Best wishes
Lee

Offline

#2 2008-11-03 16:59:20

tbo
Member
Registered: 2008-10-24
Posts: 12

Re: Restrict access to webpages?

Hi,

maybe you can realise it with a cookie that is being set if the users chooses to view your pages. I just wrote the following “plugin-snippet”, that seems to work, but does not contain very much except hiding the text and setting a cookie. Also I am not really good with textpattern or php – so perhaps one of the experts on this forum has a better idea or could check the code for some mistakes?

To use it, you have to place the <txp:restr_acc_cookieset /> tag on top of the template you use for pages with a disclaimer (before doctype-declaration). The text, available only with cookie is set between <txp:restr_acc name=“whatever”> and </txp:restr_acc>. With “name” and “value” you can set the cookies name and it’s value (obviously).

Plugin code-snippet:

# --- BEGIN PLUGIN HELP ---
 ...
# --- END PLUGIN HELP ---
<?php
}
  function restr_acc($param, $content) {
    $html = '';
    extract(lAtts(array('name' => '','value' => 'read'),$param));
    if($name == '')
      return 'restr_acc: Please enter a name for the cookie';
    $access = str_replace('"','@#@',serialize(array('name' => $name,'value' => $value)));
    if($_COOKIE[$name] == $value)
      $html = $content;
    elseif(!isset($_POST['restr_acc_cookie'])) 
      $html = 'Set Cookie?'.n.
	           '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">'.n.
	             '<input type="hidden" name="restr_acc_cookie" value="setit" />'.n.
	             '<input type="hidden" name="access" value="'.$access.'" />'.n.
	             '<input type="submit" value="Set!" />'.n.
	           '</form>'.n;
    else
      $html = 'Please refresh.'; 	   
    return $html; 
  }  
  function restr_acc_cookieset() {
    global $prefs; 
    if($_POST['restr_acc_cookie'] == 'setit') {
      $access = unserialize(str_replace('@#@','"',$_POST['access']));
      setcookie($access['name'],$access['value']);
      header('location: http://'.$prefs['siteurl'].$_SERVER['REQUEST_URI']);
    }  
  }
?>

Last edited by tbo (2008-11-03 17:01:39)

Offline

Board footer

Powered by FluxBB