Advertisement
lil_bugga

Social Network - link_checker.php

Aug 8th, 2014
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.90 KB | None | 0 0
  1. <?php
  2. $response = "";
  3.  
  4. function check_links() {
  5.     global $response;
  6.        
  7.     if(isset($_POST["fb"])){
  8.        
  9.         $dirty_fb = $_POST["fb"]; //user supplied link
  10.         $response .= check_fb($dirty_fb);
  11.     }
  12.    
  13.     if(isset($_POST["tw"])){
  14.         $dirty_tw = $_POST["tw"]; //user supplied link
  15.         $response .= check_tw($dirty_tw);
  16.     }
  17.    
  18.     if(isset($_POST["go"])){
  19.         $dirty_go = $_POST["go"]; //user supplied link
  20.         $response .= check_go($dirty_go);
  21.     }
  22.    
  23.     if(isset($_POST["in"])){
  24.         $dirty_in = $_POST["in"]; //user supplied link
  25.         $response .= check_in($dirty_in);
  26.     }
  27.    
  28.     if(isset($_POST["yt"])){
  29.         $dirty_yt = $_POST["yt"]; //user supplied link
  30.         $response .= check_yt($dirty_yt);
  31.     }
  32.    
  33.     if(isset($_POST["pe"])){
  34.         $dirty_pe = $_POST["pe"]; //user supplied link
  35.         $response .= check_pe($dirty_pe);
  36.     }
  37.    
  38.     echo $response;
  39. }
  40.  
  41. function check_fb($dirty_fb) {
  42.     global $db_conx;
  43.     global $log_username;
  44.     //remove anything before facebook.com using strstr()
  45.     //clean url leaving alphanumerics : / _ . ? = only - required to remove facebook link format with /#!/
  46.     $clean_url = strstr(preg_replace('#[^a-z0-9:/_.?=]#i', '', $dirty_fb), 'facebook.com');
  47.    
  48.     $parsed_url = parse_url("http://www.".$clean_url); //parse url to get brakedown of components
  49.    
  50.     $safe_host = $parsed_url['host']; // safe host direct from parse_url = www.facebook.com
  51.    
  52.     // str_replace to switch any // to a / inside the returned path - required due to preg_replace process above
  53.     $safe_path = str_replace("//", "/", ($parsed_url['path']));
  54.    
  55.     if ($safe_host == 'www.facebook.com' && $safe_path != '' && $safe_path != '/') {
  56.         $link = $safe_host.$safe_path;
  57.         $sql = "UPDATE useroptions SET facebook='$link' WHERE username='$log_username'";
  58.         mysqli_query($db_conx, $sql);
  59.         $var = "fb1|";
  60.         return $var;
  61.     } else if ($safe_host == 'www.facebook.com' && $safe_path == '') {
  62.         $var = "fb2|";
  63.         return $var;
  64.     } else if ($safe_host == 'www.facebook.com' && $safe_path == '/') {
  65.         $var = "fb3|";
  66.         return $var;
  67.     } else {           
  68.         $var = "fb4|";
  69.         return $var;
  70.     }
  71. }
  72.  
  73. function check_tw($dirty_tw) {
  74.     global $db_conx;
  75.     global $log_username;
  76.     //remove anything before twitter.com using strstr()
  77.     //clean url leaving alphanumerics : / _ . ? = only
  78.     $clean_url = strstr(preg_replace('#[^a-z0-9:/_.?=]#i', '', $dirty_tw), 'twitter.com');
  79.    
  80.     $parsed_url = parse_url("http://www.".$clean_url); //parse url to get brakedown of components
  81.    
  82.     $safe_host = $parsed_url['host']; // safe host direct from parse_url
  83.    
  84.     // str_replace to switch any // to a / inside the returned path - required due to preg_replace process above
  85.     $safe_path = str_replace("//", "/", ($parsed_url['path']));
  86.    
  87.     if ($safe_host == 'www.twitter.com' && $safe_path != '' && $safe_path != '/') {
  88.         $link = $safe_host.$safe_path;
  89.         $sql = "UPDATE useroptions SET twitter='$link' WHERE username='$log_username'";
  90.         mysqli_query($db_conx, $sql);
  91.         $var = "tw1|";
  92.         return $var;
  93.     } else if ($safe_host == 'www.twitter.com' && $safe_path == '') {
  94.         $var = "tw2|";
  95.         return $var;
  96.     } else if ($safe_host == 'www.twitter.com' && $safe_path == '/') {
  97.         $var = "tw3|";
  98.         return $var;
  99.     } else {           
  100.         $var = "tw4|";
  101.         return $var;
  102.     }
  103. }
  104.  
  105. function check_go($dirty_go) {
  106.     global $db_conx;
  107.     global $log_username;
  108.     //remove anything before google.com using strstr()
  109.     //clean url leaving alphanumerics : / _ . ? = only
  110.     $clean_url = strstr(preg_replace('#[^a-z0-9:/_.?=]#i', '', $dirty_go), 'plus.google.com');
  111.    
  112.     $parsed_url = parse_url("http://www.".$clean_url); //parse url to get brakedown of components
  113.    
  114.     $safe_host = $parsed_url['host']; // safe host direct from parse_url
  115.    
  116.     // str_replace to switch any // to a / inside the returned path - required due to preg_replace process above
  117.     $safe_path1 = str_replace("//", "/", ($parsed_url['path']));
  118.     $safe_path2 = str_replace(":plus:","+", $safe_path1);
  119.    
  120.     if ($safe_host == 'www.plus.google.com' && $safe_path2 != '' && $safe_path2 != '/') {
  121.         $link = $safe_host.$safe_path2;
  122.         $sql = "UPDATE useroptions SET google='$link' WHERE username='$log_username'";
  123.         mysqli_query($db_conx, $sql);
  124.         $var = "go1|";
  125.         return $var;
  126.     } else if ($safe_host == 'www.plus.google.com' && $safe_path2 == '') {
  127.         $var = "go2|";
  128.         return $var;
  129.     } else if ($safe_host == 'www.plus.google.com' && $safe_path2 == '/') {
  130.         $var = "go3|";
  131.         return $var;
  132.     } else {           
  133.         $var = "go4|";
  134.         return $var;
  135.     }
  136. }
  137.  
  138. function check_in($dirty_in) {
  139.     global $db_conx;
  140.     global $log_username;
  141.     //remove anything before instagram.com using strstr()
  142.     //clean url leaving alphanumerics : / _ . ? = only
  143.     $clean_url = strstr(preg_replace('#[^a-z0-9:/_.?=]#i', '', $dirty_in), 'instagram.com');
  144.    
  145.     $parsed_url = parse_url("http://www.".$clean_url); //parse url to get brakedown of components
  146.    
  147.     $safe_host = $parsed_url['host']; // safe host direct from parse_url
  148.    
  149.     // str_replace to switch any // to a / inside the returned path - required due to preg_replace process above
  150.     $safe_path = str_replace("//", "/", ($parsed_url['path']));
  151.    
  152.     if ($safe_host == 'www.instagram.com' && $safe_path != '' && $safe_path != '/') {
  153.         $link = $safe_host.$safe_path;
  154.         $sql = "UPDATE useroptions SET instagram='$link' WHERE username='$log_username'";
  155.         mysqli_query($db_conx, $sql);
  156.         $var = "in1|";
  157.         return $var;
  158.     } else if ($safe_host == 'www.instagram.com' && $safe_path == '') {
  159.         $var = "in2|";
  160.         return $var;
  161.     } else if ($safe_host == 'www.instagram.com' && $safe_path == '/') {
  162.         $var = "in3|";
  163.         return $var;
  164.     } else {           
  165.         $var = "in4|";
  166.         return $var;
  167.     }
  168. }
  169.  
  170. function check_yt($dirty_yt) {
  171.     global $db_conx;
  172.     global $log_username;
  173.     //remove anything before youtube.com using strstr()
  174.     //clean url leaving alphanumerics : / _ . ? = only
  175.     $clean_url = strstr(preg_replace('#[^a-z0-9:/_.?=]#i', '', $dirty_yt), 'youtube.com');
  176.    
  177.     $parsed_url = parse_url("http://www.".$clean_url); //parse url to get brakedown of components
  178.    
  179.     $safe_host = $parsed_url['host']; // safe host direct from parse_url
  180.    
  181.     // str_replace to switch any // to a / inside the returned path - required due to preg_replace process above
  182.     $safe_path = str_replace("//", "/", ($parsed_url['path']));
  183.    
  184.     if ($safe_host == 'www.youtube.com' && $safe_path != '' && $safe_path != '/') {
  185.         $link = $safe_host.$safe_path;
  186.         $sql = "UPDATE useroptions SET youtube='$link' WHERE username='$log_username'";
  187.         mysqli_query($db_conx, $sql);
  188.         $var = "yt1|";
  189.         return $var;
  190.     } else if ($safe_host == 'www.youtube.com' && $safe_path == '') {
  191.         $var = "yt2|";
  192.         return $var;
  193.     } else if ($safe_host == 'www.youtube.com' && $safe_path == '/') {
  194.         $var = "yt3|";
  195.         return $var;
  196.     } else {           
  197.         $var = "yt4|";
  198.         return $var;
  199.     }
  200. }
  201.  
  202. function check_pe($dirty_pe) {
  203.     //clean url leaving alphanumerics : / . only
  204.     $clean_url = preg_replace('#[^a-z0-9:/_.?=]#i', '', $dirty_pe);
  205.    
  206.     $parsed_url = parse_url("http://www.".$clean_url); //parse url to get brakedown of components
  207.    
  208.     return $parsed_url['host'].$parsed_url['path'];
  209. }
  210. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement