Created
January 12, 2019 15:03
-
-
Save scuba323/89c14d11a9a45e18fefb90fb3807bb86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PHP | |
// place here your database connection code | |
if (isset($_GET['id']) && intval($_GET['id']) > 0) { | |
$delay = 12*3600; // change here the number of hours how often a unique click must be counted | |
$sql_check = sprintf("SELECT COUNT(*) AS test FROM clicks WHERE link_id = %d AND visitor_ip = '%s' AND UNIX_TIMESTAMP(click_at) + %d > UNIX_TIMESTAMP(NOW())", $_GET['id'], $_SERVER['REMOTE_ADDR'], $delay); | |
if (mysql_result(mysql_query($sql_check), 0, "test") == 0) { | |
$country_sql = "SELECT country FROM ip2nation WHERE ip < INET_ATON('".$_SERVER['REMOTE_ADDR']."') ORDER BY ip DESC LIMIT 0,1"; | |
$country = mysql_result(mysql_query($country_sql), 0, "country"); | |
$sql_insert = sprintf("INSERT INTO clicks (link_id, visitor_ip, click_at, country, on_page) VALUES (%d, '%s', NOW(), '%s', '%s')", $_GET['id'], $_SERVER['REMOTE_ADDR'], $country, $_SERVER['HTTP_REFERER']); | |
mysql_query($sql_insert); | |
} | |
$sql_url = sprintf("SELECT url FROM link_table WHERE id = %d", $_GET['id']); | |
$url = mysql_result(mysql_query($sql_url), 0, "url"); | |
header("Location: ".$url); | |
exit; | |
} else { | |
header("Location: http://www.yourwebsite.com/"); | |
exit; | |
} | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
// place here your database connection code | |
if (isset($_GET['id']) && intval($_GET['id']) > 0) { | |
$delay = 12*3600; // change here the number of hours how often a unique click must be counted | |
$sql_check = sprintf("SELECT COUNT(*) AS test FROM clicks WHERE link_id = %d AND visitor_ip = '%s' AND UNIX_TIMESTAMP(click_at) + %d > UNIX_TIMESTAMP(NOW())", $_GET['id'], $_SERVER['REMOTE_ADDR'], $delay); | |
if (mysql_result(mysql_query($sql_check), 0, "test") == 0) { | |
$country_sql = "SELECT country FROM ip2nation WHERE ip < INET_ATON('".$_SERVER['REMOTE_ADDR']."') ORDER BY ip DESC LIMIT 0,1"; | |
$country = mysql_result(mysql_query($country_sql), 0, "country"); | |
$sql_insert = sprintf("INSERT INTO clicks (link_id, visitor_ip, click_at, country, on_page) VALUES (%d, '%s', NOW(), '%s', '%s')", $_GET['id'], $_SERVER['REMOTE_ADDR'], $country, $_SERVER['HTTP_REFERER']); | |
mysql_query($sql_insert); | |
} | |
$sql_url = sprintf("SELECT url FROM link_table WHERE id = %d", $_GET['id']); | |
$url = mysql_result(mysql_query($sql_url), 0, "url"); | |
header("Location: ".$url); | |
exit; | |
} else { | |
header("Location: http://www.yourwebsite.com/"); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment