1

I am very new to php so this question might be trivial. I am trying to understand if it is possible to redirect the browser from php server side to the page returned by HTTP request.

I have a HTTP Post request looking like so:

$postdata = http_build_query(
    array(
       "someData" => "data" ,
    )
);

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'content' => $postdata,
        'header'  =>
            "Cookie: someCookie" .
            'content-type: application/x-www-form-urlencoded; charset=utf-8'
    )

);

$context  = stream_context_create($opts);
$result = fopen('myWebsiteUrl', 'r', false, $context);

var_dump(stream_get_contents($result));

In the post I am being redirected to a different page with Get. I am trying to force the browser to move to the 'redirected' page. With the above code I am getting back the html of the redirected page but what I'm after is an actual redirect. The option of retrieving the redirect URL and doing the redirect myself in PHP doesn't work because the Get request has to happen within the same session as the Post.

1 Answer 1

1
header('Location: whereveryouwantogo.php?get=123456');

does a redirect for you with a GET-parameter attached. I'm not sure if I really got your question right, but I'm pretty sure you could do what you want/need with the header-command.

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

3 Comments

Like I mentioned in the last sentence, doing the redirect after the http won't work. The redirect is done within the http action.
Ah, now I get it. I don't think this is possible the way you'd like to have it.
Thanks. I thought this might be the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.