Serenade Posted September 12, 2013 Share Posted September 12, 2013 (edited) 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 September 12, 2013 by Serenade 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted September 12, 2013 Share Posted September 12, 2013 After a quick look, I noticed one thing... On the if statement, use this instead: if ($client_ip == $row["ip"]) { Notice the double "=". Sean 0 Quote Link to comment Share on other sites More sharing options...
Serenade Posted September 12, 2013 Author Share Posted September 12, 2013 After a quick look, I noticed one thing... On the if statement, use this instead: if ($client_ip == $row["ip"]) { Notice the double "=". Sean Hrm gave it a shot but no luck unfortunately... 0 Quote Link to comment Share on other sites More sharing options...
jclarke Posted September 13, 2013 Share Posted September 13, 2013 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"); ?> 0 Quote Link to comment Share on other sites More sharing options...
Serenade Posted September 26, 2013 Author Share Posted September 26, 2013 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! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.