0

I used the following code to post the values from one page to another page but don't know why for some reason the values are not posted. Can anyone help me correcting the below code, thanks.

<?php $postdata = http_build_query( array( 'destinationId' => 'E5322331-EB43-4C45-B5B1-00E455401676', 'keywords' => 'Rambouillet, France' ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); $result = file_get_contents('https://dev.ther8server.com/hotel-search/go/rambouillet-france', false, $context); header('Location:https://dev.ther8server.com/hotel-search/go/rambouillet-france'); ?> 
3
  • 1
    You redirect to the page using header. This creates a completely seperate request from the one created with file_get_contents. Commented Dec 18, 2013 at 13:46
  • 1
    Are you expecting this code to redirect you to the page you posted to and be able to debug the posted data? stream_context_create is more like a curl call. If you are trying to make persistent data between pages, try using session variables instead. Commented Dec 18, 2013 at 13:48
  • I want to transfer data from this page to another as page is not redirecting automatically I used header Location for redirection purpose. Commented Dec 18, 2013 at 14:02

1 Answer 1

1

This code causes PHP to post a form, get the $result page... and then ignore all that and redirect the client to another page.

Instead of of the header Location, you just want to echo $result;

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.