Guest User

Untitled

a guest
Jan 17th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. <?php
  2.  
  3. require('Hashids/HashGenerator.php');
  4. require('Hashids/Hashids.php');
  5. use Hashids\Hashids;
  6.  
  7. /**
  8. Database connection with user redirect and password redirect
  9. **/
  10. $db_connection = pg_connect("host=localhost dbname=test1 user=redirect password=redirect");
  11.  
  12. $url = $_SERVER['REQUEST_URI'];
  13. $split_url = split("/", $url);
  14. $query = $split_url[3];
  15. $singlepost_code = explode('?', $query)[0];
  16. $param = (explode('?', $query)[1]);
  17. $param_value = (explode('&', $param));
  18.  
  19. $ref = (explode('=', $param_value[0])[1]);
  20. $device = (explode('=', $param_value[1])[1]);
  21.  
  22. $ip = $_SERVER['REMOTE_ADDR'];
  23.  
  24. $response = file_get_contents('http://freegeoip.net/json/'.$ip);
  25. $response_text=json_decode($response,true);
  26. $country = $response_text['country_name'];
  27.  
  28. $country_id = 6;
  29.  
  30. try{
  31. if ($country == 'India')
  32. $country_id = 1;
  33. elseif($country == 'United States')
  34. $country_id = 2;
  35. elseif( $country == 'Austrailia')
  36. $country_id = 3;
  37. elseif( $country == 'United Kingdom')
  38. $country_id = 5;
  39. elseif ($country == 'Canada')
  40. $country_id = 4;
  41. else
  42. $country_id = 6;
  43.  
  44. }catch(Exception $e){
  45. $country_id = 6;
  46. }
  47.  
  48. $user_id = 1;
  49. $hashids = new Hashids();
  50. if($user_id){
  51. $hash_arr = $hashids->decode($ref);
  52. $user_id = $hash_arr[0];
  53. }
  54. $query = "select * from block as b where b.user_ID = $user_id";
  55. $result = pg_query($db_connection, $query);
  56. $is_block = false;
  57. if(pg_num_rows($result) != 0)
  58. $is_block = true;
  59. $query = "select * from tracking as t where t.post_ID = ".$singlepost[id]." and t.ip = $ip and t.user_ID = $user_id";
  60. $result = pg_query($db_connection, $query);
  61. $track_found = false;
  62. if(pg_num_rows($result) != 0)
  63. $track_found = true;
  64. if(strpos("66.249", $ip) && $is_block and $track_found){
  65.  
  66. $query = "select * fro users where id=".$user_id;
  67. $result = pg_query($db_connection,$query);
  68. if(pg_fetch_assoc($result)){
  69. $user= pg_fetch_assoc($result);
  70. $mobile = $user[mobile];
  71. $desktop = $user[desktop];
  72. $percent_reduce = $user[percent_reduce];
  73. $tracking_count = $user[tracking_count];
  74. $register_track = true;
  75. $click_ratio = ($desktop/$mobile)*100;
  76. if ($click_ratio > 10 and $device = 'desktop'){
  77. $register_track = false;
  78. }
  79. if ($tracking_count == 10 )
  80. $tracking_count = 1;
  81. else
  82. $tracking_count = $tracking_count+1;
  83. $query = 'update users set tracking_count ='.$tracking_count.' where id='.$user_id;
  84. $result = pg_query($db_connection,$query);
  85.  
  86. if($tracking_count <= 10 - $percent_reduce and $register_track){
  87. $query = 'insert into tracking (post_ID,user_ID,ip,ip_resolved,country_id,point,device) values('.$singlepost[id].','.$user_id.','.$ip.',0,'.$country_id.',0,'.$device.')';
  88. }
  89. }
  90. }
  91.  
  92. /**
  93. $str = 'SELECT * FROM posts where post_code=\''.$singlepost_code.'\'';
  94. $result = pg_query($db_connection, $str);
  95. $singlepost = none;
  96.  
  97. while($myrow = pg_fetch_assoc($result)) {
  98. $singlepost = $myrow;
  99. }
  100. **/
Add Comment
Please, Sign In to add comment