Page 1 of 1

FrontEndUsers Enhansement

Posted: Thu Aug 09, 2007 11:49 pm
by johnbmcdonald
I had a customer that needed to be able to restrict user accounts to a specific number of IP addresses.

If you are interested, here is the code:

        global $gCms;
        if( isset($params['ipcheck']) && $params['ipcheck'] ) {
              $ipnum = isset($params['maxnumip'])?$params['maxnumip']:3;
              $db =& $this->GetDb();
            $module =& $this->GetModuleInstance('FrontEndUsers');
            if( !$module ) return FALSE;
            $uid = $module->LoggedInId();         
              $sql = "SELECT distinct(ipaddress) FROM ".cms_db_prefix()."module_feusers_history
                    WHERE userid =" . $uid . " AND ipaddress IS NOT NULL";
          $dbresult = &$db->Execute($sql);
            while( $dbresult && $row = $dbresult->FetchRow()) {
                $data[] = $row;
            }   
          if( count($data) > $ipnum ) {
                $url = !empty($params['errorpage'])?$params['errorpage']:" http://localhost:90/cms/index.php?page=How-CMSMS-Works";
                header("Location:" . $url);
                exit();
          }                               
        }
Here is how you use it:
{cms_module module=CustomContent ipcheck=1 maxnumip=4 errorpage=http://google.com}

eMail me if you would like the whole CustomContent.module.php file

John

Re: FrontEndUsers Enhansement

Posted: Fri Aug 10, 2007 12:16 am
by calguy1000
it's possible to do this without modifying CustomContent.  You could have used the $customcontent_ip smarty variable
and some smarty logic.

Re: FrontEndUsers Enhansement

Posted: Fri Aug 10, 2007 12:17 am
by calguy1000
oh, I'm sorry.... this restricts people to a maximum of N distinct IP addresses.... it doesn't restrict 'which' ip addresses.