2

A friend contracted some wordpress agency to create a webpage that based on input data entered by user on a form create a custom URL to redirect to a third party API that shows some data to rent a car, this wordpress is done with elementor plugin and the problem is that when redirecting the query params separators are being encoded as html entities i.e the url must be something like www.site.com/?value1=value1&value2=value2&value3=value3 but the plugin is changing the url to www.site.com/?value1=value1&value2=value2&value3=value3 the & is being encoded to &, this agency left the work unfinished and don't want and also can't fix this, he asked me if I can fix it, I am not a wordpress developer so have been difficult for me, in other post someone said me that I can create a custom decoder php file to handle this on the rootfolder of the wordpress installation and instead of redirecting the form to the third party API I can redirect to the custom decoder on the site domain and fix the url to then redirect to the third party API but I can't get the url sent by the form in the php script I have this code right now

<?php
ob_start();

$API_BASE_URL="www.site.com/";

$bad_url={here must be the url sent by the form};

//here is fixed the url
$good_url=html_entity_decode($bad_url);

//concatenation of API_BASE_URL and goodurl
$redirect_url=&API_BASE_URL.$good_url

//redirects to fixed url
header('Location: '.$redirect_url);

exit();
?>

Also i saw that the $_SERVER['HTTP_REFERER'] can be used to get this url but this is not reliable, so I need another way to get the url of the form, how can I do this? the form will now redirect to www.misytedomain.com/custom-decoder/decoder.php/?value1=value1&amp;value2=value2&amp;value3=value3 that is the url I must use to build the url to send to the API.

EDIT:

srry if I am missexplaining for example, the form redirects right now to www.site.com/?value1=value1&amp;value2=value2&amp;value3=value3 but this won't work on the API so I will instead of redirec to that URL redirect to the location on my domain where the php file is somethin like www.mysitedomain.com/custom-decoder/decoder.php I thought that I could add the wrong query params like www.mysitedomain.com/custom-decoder/decoder.php/?value1=value1&amp;value2=value2&amp;value3=value3 take this wrong params, fix with the php logic and finally redirect to the API with correct params like www.site.com/?value1=value1&value2=value2&value3=value3 www.site.com is the api and www.mysitedomain.com is my wordpress domain

TTT2
  • 549
  • 2
  • 13
  • Use https://www.php.net/manual/en/function.parse-url.php + https://stackoverflow.com/a/5397746/2585154 – Dmitry K. Dec 23 '22 at 03:46
  • but how will I catch the url that is redirecting the form in the customdecoder.php, what I need is the url that the form is redirecting and this will change based on the inputs of this form – TTT2 Dec 23 '22 at 03:52
  • Could you explain a little more? Just step by step and what exactly do you want to get – Dmitry K. Dec 23 '22 at 03:53
  • srry if I missexplained. A form is sending wrong the query separators to a api So i created a php file that is intended to get fix the url and redirect to the api, so the form will not redirect to the API, instead will redirect to where the php file is inside my domain, this redirection will also have the bad query strings that will be fixed and then redirect to the API but i don't know how to get this url , see my edit please – TTT2 Dec 23 '22 at 03:56
  • 2
    So, you want to send wrong url to server (PHP), fix it and then redirect to correct url. Is it correct? And what exactly didn't work? – Dmitry K. Dec 23 '22 at 03:59
  • yes that is what I want but what didn't work is that I don't know how to catch this url – TTT2 Dec 23 '22 at 04:01
  • Could you share your HTML form code? – Dmitry K. Dec 23 '22 at 04:01
  • I mean something like
    – Dmitry K. Dec 23 '22 at 04:02
  • the problem is that is not a HTML form, is a plugin form that is sending the wrong url so instead of redirect to the api i will redirect to the path inside the domain where the php file is located – TTT2 Dec 23 '22 at 04:03
  • Okay, could you share what the plugin sends? Look for XHR request in your browser devtools – Dmitry K. Dec 23 '22 at 04:04
  • P.S. if you not sure, try to output var_dump($_REQUEST); in your PHP code – Dmitry K. Dec 23 '22 at 04:07
  • I can define where url the plugin send but the problem is that, the plugin encode the query params separator ```&``` to ```&``` so the values of the form are not readed by the api, I need to fix this changing the ```&amp``` to `&` before – TTT2 Dec 23 '22 at 04:07
  • this is the first post I did and the answer i got [https://stackoverflow.com/questions/74895214/create-custom-decoder-page-on-godaddy-host-that-fix-querystring-and-redirects-to/74895350](first question) this can clarify a lot what I mean here – TTT2 Dec 23 '22 at 04:09
  • Okay. Step 1: You say you can customize the URL where the user will be redirected to, so configure redirect to your PHP script. Step 2. Write var_dump($_SERVER['REQUEST_URI']); in your PHP script and show output – Dmitry K. Dec 23 '22 at 04:15
  • this returns ```string(27) "/custom-decoder/decoder.php"```, I used print to get this response – TTT2 Dec 23 '22 at 04:29
  • Don't forget to add broken query parameters to redirect url, I don't see them in your output – Dmitry K. Dec 23 '22 at 04:35
  • Oh i noticed, man this is the answer thanks a lot , please answer to select as correct, thanks you a lot :) – TTT2 Dec 23 '22 at 04:37

1 Answers1

1

Configure a redirect from plugin to your own PHP script (don't forget to add your broken query parameters) and then access wrong query parameters in $_SERVER['REQUEST_URI']

Dmitry K.
  • 3,065
  • 2
  • 21
  • 32