· 6 years ago · May 02, 2020, 11:44 PM
1// Your API Key.
2$key = 'AlvOCYuLfV8Lc4XgLv5S28xLVi84dNAL';
3
4/*
5* Retrieve the user's IP address.
6* You could also pull this from another source such as a database.
7*
8* If you use cloudflare change REMOTE_ADDR to HTTP_CF_CONNECTING_IP
9*/
10$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : $_SERVER['HTTP_CLIENT_IP'];
11
12
13// Retrieve additional (optional) data points which help us enhance fraud scores.
14$user_agent = $_SERVER['HTTP_USER_AGENT'];
15$user_language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
16
17// Set the strictness for this query. (0 (least strict) - 3 (most strict))
18$strictness = 1;
19
20// You may want to allow public access points like coffee shops, schools, corporations, etc...
21$allow_public_access_points = 'true';
22
23// Reduce scoring penalties for mixed quality IP addresses shared by good and bad users.
24$lighter_penalties = 'false';
25
26// Create parameters array.
27$parameters = array(
28 'user_agent' => $user_agent,
29 'user_language' => $user_language,
30 'strictness' => $strictness,
31 'allow_public_access_points' => $allow_public_access_points,
32 'lighter_penalties' => $lighter_penalties
33);
34
35/* User & Transaction Scoring
36* Score additional information from a user, order, or transaction for risk analysis
37* Please see the documentation and example code to include this feature in your scoring:
38* https://www.ipqualityscore.com/documentation/proxy-detection/transaction-scoring
39* This feature requires a Premium plan or greater
40*/
41
42// Format Parameters
43$formatted_parameters = http_build_query($parameters);
44
45// Create API URL
46$url = sprintf(
47 'https://www.ipqualityscore.com/api/json/ip/%s/%s?%s',
48 $key,
49 $ip,
50 $formatted_parameters
51);
52
53// Fetch The Result
54$timeout = 5;
55
56$curl = curl_init();
57curl_setopt($curl, CURLOPT_URL, $url);
58curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
59curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
60curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
61
62$json = curl_exec($curl);
63curl_close($curl);
64
65// Decode the result into an array.
66$result = json_decode($json, true);
67
68// Check to see if our query was successful.
69if(isset($result['success']) && $result['success'] === true){
70 // NOTICE: If you want to use one of the examples below, remove
71 // any lines containing /*, */ and *-, then remove * from any of the
72 // the remaining lines.
73
74 /*
75 *- Example 1: We'd like to block all proxies and send them to Google.
76 *
77 * if($result['proxy'] === true){
78 * exit(header("Location: https://google.com"));
79 * }
80 */
81
82 /*
83 *- Example 2: We'd like to block all proxies, but allow legitimate
84 *- crawlers like Google on our site:
85 *
86 * if($result['proxy'] === true && $result['is_crawler'] === false){
87 * exit(header("Location: https://google.com"));
88 * }
89 */
90
91 /*
92 *- Example 3: We'd like to block only visitors with a fraud score,
93 *- over 80, but allow crawlers such as Google:
94 *
95 * if($result['fraud_score'] >= 80 && $result['is_crawler'] === false){
96 * exit(header("Location: https://google.com"));
97 * }
98 */
99
100 /*
101 *- Example 4: We'd like to block only visitors which are a proxy with a
102 *- fraud score over 80, but allow crawlers such as Google:
103 *
104 * if(
105 * $result['proxy'] === true &&
106 * $result['fraud_score'] >= 80 &&
107 * $result['is_crawler'] === false
108 * ){
109 * exit(header("Location: https://google.com"));
110 * }
111 */
112
113 /*
114 *- Example 5: We'd like to block only visitors which are using tor.
115 *
116 * if($result['tor'] === true){
117 * exit(header("Location: https://google.com"));
118 * }
119 */
120
121 /*
122 * If you are confused with these examples or simply have a use case
123 * not covered here, please feel free to contact IPQualityScore's support
124 * team. We'll craft a custom piece of code to meet your requirements.
125 */
126}