Jump to content

Help with Limiting Free Trials to IP hook


Serenade

Recommended Posts

I found this hook to limit one account per IP. It works perfectly, except I would like to limit it only to specific products (pid=1, and pid=2).

 

If anyone has any ideas and are willing to help it'd be greatly appreciated!

 

<?php
if (!defined("WHMCS")) die("This file cannot be accessed directly");	


function checkIPIsValid($vars) {	
$result = select_query("tblorders","id",array("ipaddress"=>$_SERVER['REMOTE_ADDR']));
if (mysql_num_rows($result) != 0) {
  return  "It looks like your IP has already been used to register an account.";
}
}

add_hook("ClientDetailsValidation",1,"checkIPIsValid");
?>

Link to comment
Share on other sites

Here is the modified hook .To make it work all you need to do is set a product custom field with name Check For valid IP in the products that you want this hook to apply to. You can change the name for sure. You can set this field to admin only.

 

<?php
if (!defined("WHMCS"))
   die("This file cannot be accessed directly");

function checkIPIsValid($vars) {
   //Get all products that has Custom field
   $customfieldname = "Check For valid IP";
   $products = get_query_val('tblcustomfields', 'GROUP_CONCAT(relid)', array('fieldname' => $customfieldname, 'type' => 'product'));
   if (!empty($products)) {
       $productcondition = " AND tblproducts.id IN ($products)";
   } else {
       $productcondition = '';
   }
   $result = full_query("SELECT tblorders.id FROM tblorders JOIN tblhosting ON (tblorders.id=tblhosting.orderid) JOIN tblproducts ON (tblhosting.packageid=tblproducts.id) WHERE tblorders.ipaddress='" . $_SERVER['REMOTE_ADDR'] . "' $productcondition");
   if (mysql_num_rows($result) != 0) {
       return "It looks like your IP has already been used to register an account.";
   }
}

add_hook("ClientDetailsValidation", 1, "checkIPIsValid");
?>

Link to comment
Share on other sites

  • 1 month later...

Hey! Sorry for the super late reply, I totally forgot about this post.

 

Anyway, I tried the script but it does not seem to work. I have added the custom field to all products I wanted to limit, but it appears to be limiting all products on all orders...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated