Page 1 of 1

Forcing POST's with Header()

Posted: Fri Aug 27, 2004 11:03 am
by Gen-ik
Hi.

Does anyone know if it's possible to send/force POST variables using Header() while jumping for another page?

A quick example would be something like this..

Code: Select all

<?php

Header("This is where the POST variables might go");
Header("Location:anotherpage.php");

?>

PS. I can't use sessions.. otherwise that would be the simple solution ;)

Posted: Fri Aug 27, 2004 11:05 am
by Antnee
It's funny you should post that, I'm trying to find a solution that will automatically post a set of variables that have already been posted to one PHP page

My thread is here, not that I've had a solution yet!

Posted: Fri Aug 27, 2004 11:10 am
by feyd
cannot use header to do a post. Post is sent to a server, header is returned to the viewer.

you'll need [php_man]curl[/php_man] or [php_man]fsockopen[/php_man].

Posted: Fri Aug 27, 2004 12:02 pm
by Antnee
I find people here are great at pointing in the right direction but nobody can give me the code I need to get my faulty script working. Can you look at my thread and give me a solution?

Posted: Fri Aug 27, 2004 2:41 pm
by WaldoMonster
This is how I do it:

Code: Select all

<?php
$test = 'Some text for testing...';
?>

<form action="anotherpage.php" method="post" name="AutoPost" id="AutoPost">
    <input type="hidden" name="test" value="<?php echo $test; ?>">
    <noscript>
    <input type="submit" value="JavaScript disabled >> Manuel submit">
    </noscript>
</form>

<script type="text/javascript">
    <!--
    window.onload=function(){document.AutoPost.submit()};
    document.AutoPost.submit();
    //-->
</script>
The two different auto-submitting lines in the javascript are necessary to get it work for IE and Netscape.

Posted: Fri Aug 27, 2004 6:25 pm
by Antnee
Thanks for that, seems to work OK, now I just need to resolve some issues with my host. I've tested your solution and it works fine though so many thanks

Posted: Fri Aug 27, 2004 6:40 pm
by feyd
warning.. Waldo's solution is a bit on the unsafe side, as the user could alter the data, unless some additional protection was added.

Posted: Fri Aug 27, 2004 7:09 pm
by Antnee
I'm happy with this one myself, all that happens is that data is posted to a noticeboard (which is why I've been so bothered about timestamps etc on other threads) and if the user chose the option to send by email as well this page would pass the data on to the Form2mail script.

I think in this case that this is a suitable answer. I'll look into others as and when I need them. I have a PHP for Dummies book on it's way! ;)

Posted: Fri Aug 27, 2004 7:54 pm
by WaldoMonster
feyd wrote:warning.. Waldo's solution is a bit on the unsafe side, as the user could alter the data, unless some additional protection was added.
What do you mean with: is a bit on the unsafe side?

Posted: Fri Aug 27, 2004 7:58 pm
by feyd
the page it's loaded on can easily be stopped from passing on, and bogus data could be passed.. Javascript could be disabled, thus breaking the posting of data..

Posted: Fri Aug 27, 2004 8:21 pm
by d3ad1ysp0rk
Anyways, why is this topic STILL off track?
You don't post in others topics when you already have your own..

Gen-ik, what about saving the values to a temp table with their IP/timestamp and retrieving that on the next page?

Posted: Sat Aug 28, 2004 3:48 am
by Antnee
LiLpunkSkateR wrote:Anyways, why is this topic STILL off track?
You don't post in others topics when you already have your own..
I assume you're referring to me posting about my problem here too?

Gen-ik, I'm sorry, but I figured it was related to mine and I feel that WaldoMonster's solution may help Gen-ik too, so whats the big deal?

Thanks for all your help guys!