Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Adds as many as needed to the url and updating old ones
- function correct_link($mod, $force_fresh = FALSE, $url = FALSE){
- // If $url wasn’t passed in, use the current url
- if($url === FALSE){
- $scheme = $_SERVER['SERVER_PORT'] == 80 ? 'http' : 'https';
- $url = $scheme.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
- }
- // Parse the url into pieces
- $url_array = parse_url($url);
- // Force only to use passed in params
- if($force_fresh === FALSE){
- // The original URL had a query string, modify it.
- if(!empty($url_array['query'])){
- parse_str($url_array['query'], $query_array);
- foreach ($mod as $key => $value) {
- $query_array[$key] = $value;
- }
- }else{
- $query_array = $mod;
- }
- }else{
- $query_array = $mod;
- }
- return $url_array['scheme'].'://'.$url_array['host'].$url_array['path'].'?'.http_build_query($query_array);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement