-
Notifications
You must be signed in to change notification settings - Fork 1
/
click.php
64 lines (64 loc) · 2.49 KB
/
click.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/*
# This file counts clicks from users and update to db
# After counting a click for a site makes sure that a user can not click for the same site again
# We will set cookie and add IP in db for tracking
*/
// include configuration file
include('config.php');
include('assets/include/header.php');
include('assets/include/navbar.php');
//set variables
$id=$_GET['id'];
$url=$_GET['url'];
// Get user IP for tracking
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$ip2 = $_SERVER['REMOTE_ADDR'];
//Check if everything is ok
if(!empty($id) || ctype_digit($id)){
//if ok, then procceed
$q=mysql_query("SELECT * FROM `topsite` WHERE id='".$id."'");
// check if user have already Clicked for a site
$qip = mysql_query("SELECT * FROM `ips` WHERE id='".$id."' AND ip='".$ip."' OR ip2='".$ip2."'");
if (mysql_num_rows($qip)>0) {
$ip_saved = 1;
}
if(mysql_num_rows($q)>0) {
$cid = $id;
echo "Checking ID.<br />";
}
if(!isset($_COOKIE["Clicked_ID".$cid]) && (isset($cid))) {
echo "Setting cookie.<br />";
setcookie("Clicked_ID".$cid, "iD:".$id." ip:".$ip." / ".$ip2, time() + (86400 * 30), "/"); // 86400 = 1 day
$set_true = 1; // So we know the cookie has been set
echo "Cookie set.<br />";
}
// first check if requested site is available
if(($set_true == 1) && ($ip_saved == 0)) { //set_true for quicker testing.
echo "Checking cookie.<br />";
// if click set, then procceed
mysql_query("UPDATE `topsite` SET clicks=clicks+1 WHERE id='".$id."'");
mysql_query("INSERT INTO `ips` (id, ip, ip2) VALUES ('".$id."','".$ip."','".$ip2."')");
echo 'Redirecting... (1)';
sleep(2);
echo '<script>window.location.replace("/go/?id='.$id.'&url='.$url.'&cid='.$cid.'")</script>';
} else {
// everything is okay, redirect user to website
echo 'Redirecting... (0)';
sleep(2);
echo '<script>window.location.replace("/go/?id='.$id.'&url='.$url.'&cid='.$cid.'")</script>';
}
if(mysql_num_rows($q) == 0) {
// site not found, show warning to user and returning to home
echo '<body onload="javascript:alert(\'Sorry, the site you are looking for cannot be found. You are being redirected to home page.\');">
Click <a href="/">here</a> if you are not redirected automatically.';
}
} else {
// if not, then show warning and redirect to home page
echo '<body onload="javascript:alert(\'Sorry, something went wrong. You are being redirected to home page.\');">
Click <a href="/">here</a> if you are not redirected automatically.';
}
// Close MySQL connection
include('assets/include/footer.php');
mysql_close();
?>