Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP forward data post

Tags:

php

I am trying to forward data from one page to another without using cURL, is this possible?

At the moment i have tried

header('HTTP/1.1 307 Temporary Redirect');
header('Location: new-location.php');

This works nicely but gives a stupid pop up box, any other methods?

I have tried using curl but nothing happens, not sure if its enabled on my server!

like image 391
Lunar Avatar asked May 30 '11 19:05

Lunar


1 Answers

I think following is the only possible way to achieve that, instead of redirecting with location header, send this html:-

<!DOCTYPE html>
<html>
    <body onload="document.forms[0].submit()">
        <form action="new-location.php" method="post">
            <?php foreach( $_POST as $key => $val ): ?>
                <input type="hidden" name="<?= htmlspecialchars($key, ENT_COMPAT, 'UTF-8') ?>" value="<?= htmlspecialchars($val, ENT_COMPAT, 'UTF-8') ?>">
            <?php endforeach; ?>
        </form>
    </body>
</html>
like image 137
Salman von Abbas Avatar answered Sep 27 '22 18:09

Salman von Abbas