PHP - How to get query params sent to script - php

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&value2=value2&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&value2=value2&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&value2=value2&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

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']

Related

Generate a search URL with php and redirect through HTML link

I'm trying to access a search-generated URL without actually going to the search results page. Essentially this is the process I would like to mimic:
go to google
type in "cat toys"
copy the new search-generated URL with all the unique get parameters
Is there a way to send that sort of request through php, receive that URL, then pass that URL into a header("Location: googlePage") function?
So essentially the php would look like this:
<? php
$link = ...get google url...
header("Location: ".$link);
?>
I'm trying to manage a certain web app that gets some of its info from a website that auto generates unique URLs each time the page is loaded. I'm assuming it has to do with time stamps being encoded. So even if you refresh the page, the GET parameters will be different. Time stamps are the only thing I can think of that might change this. Either way, the point of my question is I would like to send the request through php, get that URL and send that new URL to my redirect. Is this possible in some kind of way?

How can I get the page that sent a request to my REST API?

I am trying to retrieve the full URL of the page that uses an API.
Like: index.php makes a call to the API for homepage content. I'd like to be able to know if that request actually came from index.php or if it originated from a different page on the site.
I had thought I could use $_SERVER['PHP_SELF'] but that's returning the API's URL every time. Beyond that I can require an additional parameter and just send over the current URL with the request, but I'd like to avoid doing this if it's possible.
The end goal is to see whether the request is being viewed on the actual API page for tests, or if it's really being used in the wild.
You should use $_SERVER['REQUEST_URI'] which contains the URL of the page which request came from.
More info here

How to call an elgg module action via url

Im new to Elgg, My requirement is to create an Elgg plugin to import contact from Gmail,Yahoo and MSN.
I already successfully imported the contacts in Joomla. when I create an Elgg plugin and the Oauth call back url given like invitefriends/gmailcallback or even direct call like
mod/invitefriends/actions/gmailcallback.php
Its not working.
In first case it return form token missing I tried to add form token dynamically like below.
$ts = time();
elgg_register_action('invitefriends/gmailcallback',
TRUE,
elgg_get_plugins_path() . 'invitefriends/actions/gmailcallback.php?__elgg_token='.generate_action_token($ts).'&__elgg_ts='.$ts);
But still same error.
so I tried to access module file directly it works fine ,but the problem is I didn't get the $_SESSION['oauth_token_secret'] session variable are not getting, it set in default view and have proper value but unable to get that session in action file in direct call method.
Iam not sure its in Elgg standard, Please advice me to solve the problem
Thanks in advance..
Don't use direct call. First thing: you're using deprecated action registration parameters - update your call. I assume you're writing to Elgg 1.8 or later.
You're additng action tokens in completely wrong way! They're necessary to prevent XSRF attacks, so need to pe added at URL generation. To elgg_register_action, you need to pass action file PATH, not URL. Use elgg_add_action_tokens_to_urland read through http://docs.elgg.org/wiki/Actions#Security
You should get specific error telling you that, but you didn't mention it.

How to redirect to an external url along with POST argument without building any form in drupal?

I am trying to talk to a gateway. For this I am first taking clients information then procesing it. After processing is done I redirect user to another blank page where I fill up hidden form fields with parameters for 3D secure connection which then redirect user to third party page. Hence there are 3 redirection. I want to remove 2nd redirection and instead send post data to url with redirection without building any form. I am looking into drupal_http_request, but it seems it only posts parameters and don't forward user to action url.
What can I do?
drupal_http_request() does allow POST but it defaults to GET. It also returns redirect url if the returned request specifies one. I'd give drupal_http_request() in a custom module a try though before resorting to curl.

Passing URL as Argument to PHP file

I'm writing a php script that will fetch data from a given URL and then run a lot of calculations based on that data, and then output it for the user.
The web page in question is a page with an embedded iframe. The iframe contains javascript code that contains the data I need, and unfortunately, the iframe is not hosted on the same domain as the web page. So what I'm trying to do is extract the URL to the iframe from the web page (I can at least do that without hitting cross-domain restrictions), and then pass the URL to the php file, and it will load that URL, and find the information.
This raises a slight problem of the URL having lots of arguments it in already. It's shaped in the form of www.somesite.com/iframe.php?userstring=asfjkl&arg1=654&arg2=132%2C9848%2C698
The problem is that the URL already has arguments, and this will not work well for my php file, which will confuse those arguments being arguments, instead of being part of the URL when I redirect the user to my site's URL of mysite.com/test.php?URL=(string shown above). So now, I'm thinking about a POST request, but sending a POST request will not redirect the users unless I actually have a form. So my question is, if that is a viable idea, to send the URL by creating an invisible form and setting the data to the URL, then submitting it, and if cross domain submission for form is allowed. (I think it is). Any other suggestions?
Simply urlencode() the URL argument. Then everything works fine.
urlencode('http://www.example.com/blah?x=y&a=123&something=else');
// Returns http%3A%2F%2Fwww.example.com%2Fblah%3Fx%3Dy%26a%3D123%26something%3Delse

Categories