Jump to content

Limit free trials to IP hook


Serenade

Recommended Posts

I wrote this hook to limit one free trial per IP. I can't figure out why it's not working, and as far as I can tell it should. Any ideas?

 

<?php
if (!defined("WHMCS")) die("This file cannot be accessed directly");	
function checkIPIsValid($vars) {
global $errormessage,$client_ip;				
$result = select_query("tblclients","ip",array("ip"=>$client_ip));
while ($row = mysql_fetch_array($result)) {
	if ($client_ip = $row["ip"]) {
		$errormessage .= "<li>Your IP has already been used to register an account, please login to that account to place an order.";
	}
	break;
}
}
add_hook("ClientDetailsValidation",0,"checkIPIsValid","");
?>

Edited by Serenade
Link to comment
Share on other sites

There were a couple of things wrong, I went ahead and fixed this up for you. Also, I changed the query to look at the tblorders tables for ip addresses and not tblclients. The ip in tblclients changes each time a client logs in from a new location. I also added a check to make sure this validation only runs for new clients otherwise what you had would prevent a client from updating their information.

 

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


function checkIPIsValid($vars) {	
 if ($vars["custtype"] == "new") {	
   $result = select_query("tblorders","id",array("ipaddress"=>$_SERVER['REMOTE_ADDR']));
   if (mysql_num_rows($result) != 0) {
     return  "<li>Your IP has already been used to register an account, please login to that account to place an order.";
   }
 }
}

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

Link to comment
Share on other sites

  • 2 weeks later...
There were a couple of things wrong, I went ahead and fixed this up for you. Also, I changed the query to look at the tblorders tables for ip addresses and not tblclients. The ip in tblclients changes each time a client logs in from a new location. I also added a check to make sure this validation only runs for new clients otherwise what you had would prevent a client from updating their information.

 

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


function checkIPIsValid($vars) {	
 if ($vars["custtype"] == "new") {	
   $result = select_query("tblorders","id",array("ipaddress"=>$_SERVER['REMOTE_ADDR']));
   if (mysql_num_rows($result) != 0) {
     return  "<li>Your IP has already been used to register an account, please login to that account to place an order.";
   }
 }
}

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

 

Thanks buddy, you rock!

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