Advertisement
Guest User

Untitled

a guest
May 11th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. // Adds as many as needed to the url and updating old ones
  2. function correct_link($mod, $force_fresh = FALSE, $url = FALSE){
  3.     // If $url wasn’t passed in, use the current url
  4.     if($url === FALSE){
  5.         $scheme = $_SERVER['SERVER_PORT'] == 80 ? 'http' : 'https';
  6.         $url = $scheme.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  7.     }
  8.  
  9.     // Parse the url into pieces
  10.     $url_array = parse_url($url);
  11.  
  12.     // Force only to use passed in params
  13.     if($force_fresh === FALSE){
  14.        
  15.         // The original URL had a query string, modify it.
  16.         if(!empty($url_array['query'])){
  17.             parse_str($url_array['query'], $query_array);
  18.             foreach ($mod as $key => $value) {
  19.                     $query_array[$key] = $value;
  20.             }      
  21.         }else{
  22.             $query_array = $mod;
  23.         }
  24.     }else{
  25.         $query_array = $mod;  
  26.     }
  27.    
  28.     return $url_array['scheme'].'://'.$url_array['host'].$url_array['path'].'?'.http_build_query($query_array);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement