views:

491

answers:

2

Hi I have a php srcript that receives GET data and I want to redirect the data from GET to another page in wordpress using POST. It's that possible, and how?

Thank's for the help.

+1  A: 

Only using form and javascript, which is not bulletproof.

Michael Krelin - hacker
Can't this be made whith PHP using CURL?
andreeib
That wouldn't be a redirect. Yes, I think you can manually call out with `curl` and deliver back the results.
Michael Krelin - hacker
Well it does not necesary be a redirect, I just have to send the GET varaibles to a page using POST. Also do you know how to make this unsing Curl.
andreeib
Full answer would pretty lengthy, but basically, you create curl request, populate its parameters (see `curl_setopt`) and perform the request. I think the documentation will give you more details and faster than I can.
Michael Krelin - hacker
A: 

The only way this could be done in pure PHP is by using cURL and printing the result of that request in the page:

<?php

// sort post data
$postarray = array();
foreach ($_GET as $getvar => $getval){
    $postarray[] = $getvar.'='.urlencode($getval);
    }
$poststring = implode('&',$postarray);

// fetch url
$curl = curl_init("http://www.yourdomain.com/yourpage.php");
curl_setopt($ch,CURLOPT_POST,count($postarray));
curl_setopt($ch,CURLOPT_POSTFIELDS,$poststring);
$data = curl_exec($curl);
curl_close($curl);

// print data
print $data;

?>

Obviously you'd validate the GET data before you post it. If there's another way you can do this I'd be interested to know as this method is not ideal. Firstly, cURL must be enabled in PHP, and secondly there will be some overhead in requesting another URL.

Rowan
Thank's alot I will try your code, for the moment I am putting the data into a cookie in the first page and the reading it from the second page, but this will only work for pages in the same domain.
andreeib
`$_SERVER['QUERY_STRING']` is a precomposed string with the querystring, so you don't need to construct `$poststring`.
Casey Hope