Page 1 of 2
Can you execute a post command from code?
Posted: Mon May 16, 2005 3:18 am
by icarpenter
Hi I was wondering if there is any way that you can execute a post command from code...
For example I would like to be able to send a variable value to another page without physically pushing a form button.
I can do this via a <meta> appending the variable to the URL see below.
Code: Select all
echo"<META HTTP-EQUIV=Refresh CONTENT='0; URL=http://mypage.php?variable=value'>";
But I would like to keep the variables hidden.
I would be greatful for any ideas!
Posted: Mon May 16, 2005 3:44 am
by phpScott
you could always use sessions to pass the varialbes around if you need to.
Posted: Mon May 16, 2005 3:53 am
by icarpenter
Yeah I could write to a session variable and call the page via the <meta> method, but would me much cleaner to use a POST method if one exists.
Posted: Mon May 16, 2005 4:21 am
by anjanesh
I was once saw this somewhere - someone was doing this but had problems - I was very surprised to find that it could be done that way.
I copied some code but didn't copy the link.
This is the code.
Code: Select all
$ReqHeader =
"POST $URI HTTP/1.0\n".
"Host: $Host\n".
"User-Agent: PostIt\n".
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length: $ContentLength\n\n".
"$ReqBody\n";
// echo $ReqHeader;
Let me try searching for the exact link.
Posted: Mon May 16, 2005 4:35 am
by patrikG
use a <div> and refresh the content by using javascript's submit() function.
Posted: Mon May 16, 2005 4:43 am
by anjanesh
Posted: Mon May 16, 2005 5:13 am
by icarpenter
patrikG wrote:use a <div> and refresh the content by using javascript's submit() function.
Would this method only refresh the information that is in the current <div> and would yo have a code example?
Posted: Mon May 16, 2005 5:25 am
by icarpenter
[quote="anjanesh"]I was once saw this somewhere - someone was doing this but had problems - I was very surprised to find that it could be done that way.
[quote]
Anjanesh have tried this but just seems print a new page and doesn't post any values...
Posted: Mon May 16, 2005 5:29 am
by Chris Corbyn
fsockopen() is used to send HTTP requests amongst other things

Posted: Mon May 16, 2005 6:38 am
by John Cartwright
Posted: Mon May 16, 2005 7:49 am
by onion2k
Code: Select all
header("Location: mypage.php?variable=value");
exit;
I've never had any problems with that. But a clever person could still read the variable..
Posted: Mon May 16, 2005 8:42 am
by icarpenter
[quote="onion2k"]
Code: Select all
header("Location: mypage.php?variable=value");
exit;
Tried that but got an error:
Warning: Cannot modify header information - headers already sent by (output started at C:\mypage.php:9)
Do I have to kill the existing header somehow?
Posted: Mon May 16, 2005 9:54 am
by phpScott
that is correct. the header() must be the first thing that is being sent.
do a search on this site there are lots of questions and anwsers about using header()
Posted: Mon May 16, 2005 9:55 am
by anjanesh
Make sure theres no output (to the browser) before header() call.
Posted: Mon May 16, 2005 3:02 pm
by hedge
Check out this link for some functions I wrote to do a POST using fsockopen
viewtopic.php?t=7063 You could also use CURL or snoopy.