How do you send post variables in php using header? If you can’t, how do you do it some other way? I do not want to use forms or javascript or anything.
I got this code off of a [URL=http://www.faqts.com/knowledge_base/view.phtml/aid/12039/fid/51]website
– It’s unacceptably slow, and
– It doesn’t actually redirect when I call the function!
Here’s the code:
[code=php]
function sendToHost($host,$method,$path,$data,$useragent=0)
{
// Supply a default method of GET if the one passed was empty
if (empty($method)) {
$method = ‘GET’;
}
$method = strtoupper($method);
$fp = fsockopen($host, 80);
if ($method == ‘GET’) {
$path .= ‘?’ . $data;
}
fputs($fp, “$method $path HTTP/1.1rn”);
fputs($fp, “Host: $hostrn”);
fputs($fp,”Content-type: application/x-www-form- urlencodedrn”);
fputs($fp, “Content-length: ” . strlen($data) . “rn”);
if ($useragent) {
fputs($fp, “User-Agent: MSIErn”);
}
fputs($fp, “Connection: closernrn”);
if ($method == ‘POST’) {
fputs($fp, $data);
}
while (!feof($fp)) {
$buf .= fgets($fp,128);
}
fclose($fp);
return $buf;
}
What should I do??????
Why would you want to do such a thing anyway?[/QUOTE]
It's not possible to do that because header('Location: [...]'); diverts to a URL and URLs don't contain POST data.[/QUOTE]
I do not want to use forms or javascript or anything.[/QUOTE]
• Don't respond saying "Why don't you ..." when I state in my previous post "I don't want to ..."[/QUOTE]
I need variables passed to activate appropriate code on the page.[/QUOTE]Why is the script using the POST method? Is the outcome of the script idempotent?
[code=php]
if($_POST['whattodo'] == "functiona"){
echo "Hello! How are you today?";
} else {
echo "Goodbye!";
}
[/code]
Well that is not idempotent so should be using the GET method.[code=php]
if($_POST['whattodo'] == "functiona"){
echo "Hello! How are you today?";
} else {
echo "Goodbye!";
}
[/code]
That's like the code on the headered page.[/QUOTE]
[code=php]
header("HTTP/1.0 307 Temporary redirect");
header("Location: http://www.example.com/filename");
exit();
[/code]
That sounds good, but is there a way to dynamically submit the forms without using JavaScript?
[color=white].[/color] [/QUOTE]
I didn't use any Java Script. It is all HTML. It just needs a click on a button.[/QUOTE]Wellthat could be combined with a javascript auto submit so the button only shows if javascript is disabled.
Some people have javascript disabled. I want my program to work for almost everybody.[/QUOTE]Well almost everyone has javascript enabled. Javascript is considered part of the default interface. Do you really want to be programming your site so it works flawlessly for people that delibrately disable components of the default interface? It just means these "clever" individuals will need to press a button. And don't believe any rubbish about accessibility. All modern software to aid people with accessibility problems does not have any problem running Javascript.
I got this code off of a website, but there are two problems [U][B][I]etc...[/I][/B][/U][/QUOTE]
I think the code that I posted in the first post will work, but how do you make it actually reload the browser???[/QUOTE]
And what about that [U]sendToHost();[/U] function? It seems like it should work; I guess the speed is okay, but what function do I have to put it in to make it redirect? Do I use it first then header the page ?[/QUOTE]
Thanks everyone! The more specific problem is that I [I]already have working code on the targeted page[/I], and I don't want to change it.[/QUOTE]
would you already have a working application if you'd just gone ahead and modified that page with the additional functionality that you need?[/QUOTE]
0.1.9 — BETA 5.5