Forcing POST's with Header()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Forcing POST's with Header()

Post 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 ;)
Antnee
Forum Newbie
Posts: 24
Joined: Fri Aug 27, 2004 7:04 am
Location: Nottingham

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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].
Antnee
Forum Newbie
Posts: 24
Joined: Fri Aug 27, 2004 7:04 am
Location: Nottingham

Post 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?
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post 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.
Antnee
Forum Newbie
Posts: 24
Joined: Fri Aug 27, 2004 7:04 am
Location: Nottingham

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Antnee
Forum Newbie
Posts: 24
Joined: Fri Aug 27, 2004 7:04 am
Location: Nottingham

Post 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! ;)
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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?
Antnee
Forum Newbie
Posts: 24
Joined: Fri Aug 27, 2004 7:04 am
Location: Nottingham

Post 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!
Post Reply