Member Avatar for ingeva

I have written this small test script:

<html>
<body>
<?php
if ($_POST['amount'])
{	foreach ($_POST as $key => $in)
	{	echo $key;
		echo "=";
		echo $in;
		echo "<br />";
	}
	exit ('</body></html>');
}
?>

Form output:
<form id='transfer' method='POST' action='transfer.php'>
<input type='hidden' name='touser' value="inge">
<input type='hidden' name='amount' value="1000">
<input type='hidden' name='note' value='Contratulations! You won!'>
<input type='hidden' name='action' value='transfer'>
</form>
<script type="text/JavaScript">
function Submit(form)
{	document.getElementById(form).submit();
}
Submit('transfer');
</script>

</body>
</html>

The script works, but I would like to sent the POST data using the php "header" function instead so the headers don't pass from the client.

The problem is that I can't find any description of the format to be used.

Even in a comprehensive php book I can't find anything about it.
Can anyone help?

Recommended Answers

All 6 Replies

If you are talking about when going from one page to $_POST data is submitted then their might be a chance of doing it with curl but instead I would recommend using sessions.

The script works, but I would like to sent the POST data using the php "header" function instead so the headers don't pass from the client.

I am quite confused what you actually want. If you want to redirect the user to some other page using header function, you can pass the POST data in the query string. header("location: somepage.php?name=$name&age=$age");

Member Avatar for ingeva

If you are talking about when going from one page to $_POST data is submitted then their might be a chance of doing it with curl but instead I would recommend using sessions.

I can't use sessions in this case, since the "action" script only accepts POST.

In the meantime I've found something about POST but I don't fully understand how to implement it:

POST /path/script.cgi HTTP/1.0
    From: frog@jmarshall.com
    User-Agent: HTTPTool/1.0
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 32

    home=Cosby&favorite+flavor=flies

I can probably find out how to use this by some experimenting but if someone has a working example I'd be grateful.

Things I wonder about are:
Does the receiving end return information that I need to handle?
Is the sender's mail address necessary?

Thanks!

I think I totally misunderstood your question! My apologies. :)

Member Avatar for ingeva

I think I totally misunderstood your question! My apologies. :)

No problem!

The situation is that I want to transfer some data using POST. It's the only alternative since the action script expects it, and I don't have access to that script.

I have experimented with placing the POST text in a string and send it using header(), but I keep getting error messages. The header function obviously doesn't accept multiple lines, and splitting it up doesn't work either.

Probably the easiest way is the method used in #1, but that requires client cooperation and JavaScript. I was hoping to be able to avoid that.

Oh, BTW, in one of my own systems I use $_SESSION. It has all the advantages and none of the drawbacks! :)

I am quite confused what you actually want. If you want to redirect the user to some other page using header function, you can pass the POST data in the query string. header("location: somepage.php?name=$name&age=$age");

Hi,

I want to redirect from current page to previous page with some information stored.
So, I have Hello.php where i fill out form with user's first name, last name, item name and submit.
I have set form submit action="db.php". "db.php" will add the user item to database and calls header('Location: Hello.php?firstName=abc&lastName=xyz');

Database operation is working fine. The header() is redirecting my page to Hello.php. But, the firstname and lastname will not appear in the form text boxes.

Am i doing it correct????
Can anyone help me?

SwatK

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.