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
icarpenter
Forum Commoner
Posts: 84 Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England
Post
by icarpenter » Mon May 16, 2005 3:18 am
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!
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Mon May 16, 2005 3:44 am
you could always use sessions to pass the varialbes around if you need to.
icarpenter
Forum Commoner
Posts: 84 Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England
Post
by icarpenter » Mon May 16, 2005 3:53 am
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.
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Mon May 16, 2005 4:21 am
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.
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Mon May 16, 2005 4:35 am
use a <div> and refresh the content by using javascript's submit() function.
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Mon May 16, 2005 4:43 am
icarpenter
Forum Commoner
Posts: 84 Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England
Post
by icarpenter » Mon May 16, 2005 5:13 am
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?
icarpenter
Forum Commoner
Posts: 84 Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England
Post
by icarpenter » Mon May 16, 2005 5:25 am
[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...
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Mon May 16, 2005 7:49 am
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..
icarpenter
Forum Commoner
Posts: 84 Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England
Post
by icarpenter » Mon May 16, 2005 8:42 am
[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?
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Mon May 16, 2005 9:54 am
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()
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Mon May 16, 2005 9:55 am
Make sure theres no output (to the browser) before header() call.
hedge
Forum Contributor
Posts: 234 Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada
Post
by hedge » Mon May 16, 2005 3:02 pm
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.