get url redirection - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of get url redirection.php

  1. <?php
  2.  
  3. function get_parameters($url){
  4.         $components = parse_url($url, PHP_URL_QUERY);
  5.         @parse_str($components, $results);
  6.         return (is_array($results))?$results:[];
  7. }
  8.  
  9. // georges variation render
  10. // set get for exemple comment bellow line for production
  11. $_GET=array("name"=>"test","utm_content"=>"V3","utm_source"=>"ag2");
  12. $render_variation = 'https://www.geeksforgeeks.org/register?name=oda';
  13.  
  14. // calculate new parameters for redirection
  15. if(is_array($_GET)){
  16.         $new_parameters = array_diff_key($_GET,get_parameters($render_variation));
  17. } else {
  18.         $new_parameters=[];
  19. }
  20. // final parameters
  21. $final_parameters = array_merge(get_parameters($render_variation),$new_parameters);
  22. // final url 
  23. $redirect_url = strtok($render_variation,'?')."?".http_build_query($final_parameters);
  24.  
  25. print_r($redirect_url);
  26.  
  27. ?>
File Description
  • get url redirection
  • PHP Code
  • 28 Apr-2022
  • 799 Bytes
You can Share it: