Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require('Hashids/HashGenerator.php');
- require('Hashids/Hashids.php');
- use Hashids\Hashids;
- /**
- Database connection with user redirect and password redirect
- **/
- $db_connection = pg_connect("host=localhost dbname=test1 user=redirect password=redirect");
- $url = $_SERVER['REQUEST_URI'];
- $split_url = split("/", $url);
- $query = $split_url[3];
- $singlepost_code = explode('?', $query)[0];
- $param = (explode('?', $query)[1]);
- $param_value = (explode('&', $param));
- $ref = (explode('=', $param_value[0])[1]);
- $device = (explode('=', $param_value[1])[1]);
- $ip = $_SERVER['REMOTE_ADDR'];
- $response = file_get_contents('http://freegeoip.net/json/'.$ip);
- $response_text=json_decode($response,true);
- $country = $response_text['country_name'];
- $country_id = 6;
- try{
- if ($country == 'India')
- $country_id = 1;
- elseif($country == 'United States')
- $country_id = 2;
- elseif( $country == 'Austrailia')
- $country_id = 3;
- elseif( $country == 'United Kingdom')
- $country_id = 5;
- elseif ($country == 'Canada')
- $country_id = 4;
- else
- $country_id = 6;
- }catch(Exception $e){
- $country_id = 6;
- }
- $user_id = 1;
- $hashids = new Hashids();
- if($user_id){
- $hash_arr = $hashids->decode($ref);
- $user_id = $hash_arr[0];
- }
- $query = "select * from block as b where b.user_ID = $user_id";
- $result = pg_query($db_connection, $query);
- $is_block = false;
- if(pg_num_rows($result) != 0)
- $is_block = true;
- $query = "select * from tracking as t where t.post_ID = ".$singlepost[id]." and t.ip = $ip and t.user_ID = $user_id";
- $result = pg_query($db_connection, $query);
- $track_found = false;
- if(pg_num_rows($result) != 0)
- $track_found = true;
- if(strpos("66.249", $ip) && $is_block and $track_found){
- $query = "select * fro users where id=".$user_id;
- $result = pg_query($db_connection,$query);
- if(pg_fetch_assoc($result)){
- $user= pg_fetch_assoc($result);
- $mobile = $user[mobile];
- $desktop = $user[desktop];
- $percent_reduce = $user[percent_reduce];
- $tracking_count = $user[tracking_count];
- $register_track = true;
- $click_ratio = ($desktop/$mobile)*100;
- if ($click_ratio > 10 and $device = 'desktop'){
- $register_track = false;
- }
- if ($tracking_count == 10 )
- $tracking_count = 1;
- else
- $tracking_count = $tracking_count+1;
- $query = 'update users set tracking_count ='.$tracking_count.' where id='.$user_id;
- $result = pg_query($db_connection,$query);
- if($tracking_count <= 10 - $percent_reduce and $register_track){
- $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.')';
- }
- }
- }
- /**
- $str = 'SELECT * FROM posts where post_code=\''.$singlepost_code.'\'';
- $result = pg_query($db_connection, $str);
- $singlepost = none;
- while($myrow = pg_fetch_assoc($result)) {
- $singlepost = $myrow;
- }
- **/
Add Comment
Please, Sign In to add comment