Click to See Complete Forum and Search --> : automatically pass values from php to a .pl file
luckyluk
04-02-2005, 09:50 AM
Hi folks. This one is probably pretty simple. I have a .php file that I am using using for check some things and set some values. Based on certain conditions, I need to be able to some of the values to a .pl file. All of this is happening behind the scenes, so there will be no user interaction. So, how do I perform a "POST" from a .php file to a .pl file automatically?
Thanks.
winged1
04-02-2005, 10:21 AM
I have had problems passing values in such a manner, led me to implement perl to handle the whole solution rather than splitting back forth.
luckyluk
04-02-2005, 10:59 AM
There has got to be a pretty simple way of doing this. How do you pass values from one php file to another without the user having to click on something?
luckyluk
04-02-2005, 11:57 AM
Hi, I just want to make sure that everyone understands what it is I am trying to do. Here are more details. Hopefully this will help clear any confusion up.
The only reason I am doing this, is to avoid the user having to click a second time. Here is the scenario:
page1.html
User fills out form then clicks submit. The form performs a POST method to page2.php
page2.php
conditions are checked and new variables are set with appropriate values.
Here is the part I need help with. I need to send the variables that I have set in this php file to the .pl file as if I had sent it via <form action=http://www.site.com/page3.pl" method="POST">. I may not be using the correct terminology, but I need to perform an automatic post, automatic form submission or whatever you want to call it. I just need to be able to perform this action without the user having to click on a button again.
page3.pl (This is not a form that I have control of and is located on anther site.)
Does whatever it does, but is expecting the data by way of a POST.
Thanks
NogDog
04-02-2005, 12:47 PM
You might want to take a look at this: http://nf.wh3rd.net/projects/http.inc/http.inc
(I have not tried it, just found it while searching about a bit.)
luckyluk
04-02-2005, 01:02 PM
You might want to take a look at this: http://nf.wh3rd.net/projects/http.inc/http.inc
(I have not tried it, just found it while searching about a bit.)
I don't know what this page is, but I can't get it to load.
solomon
04-02-2005, 02:08 PM
Are you certain the variables need to be POSTed? Is the .pl script looking for POST or just REQUEST? I really don't know about .pl but the following would certainly work for php GET and REQUEST - it may not be the most elegant solution but I think it will certainly serve your requirements:
At the bottom of page2.php, when all the conditions are checked and the variables have been set, include comething like this:
<?php
$location = "http://www.site.com/page3.pl?var1=".$var1."&var2=".$var2."&var3=".$var3;
header ('location:'.$location);
?>
However. if POSTing is absolutely essential, I reckon there's probably a javascript way of doing it - by automatically submitting a form by POST onLoad. Maybe try asking in the js forum.
DARTHTAMPON
04-02-2005, 02:31 PM
why are you using another page to validate and change values? This can be easily done with javascript and than you do not need to be passing values by hand. By doing this you would save bandwidth because the info gets checked on the client side instead of passing the info back and forth. If you can not send validation/variable changes to the users machine because of sensitivity why not pass the information directly to the pl file and do the checking befor you do what ever you planned to do. if something is not correct you can redirect back to the original.
luckyluk
04-02-2005, 03:00 PM
why are you using another page to validate and change values? This can be easily done with javascript and than you do not need to be passing values by hand. By doing this you would save bandwidth because the info gets checked on the client side instead of passing the info back and forth. If you can not send validation/variable changes to the users machine because of sensitivity why not pass the information directly to the pl file and do the checking befor you do what ever you planned to do. if something is not correct you can redirect back to the original.
I don't want to have to rely on Javascript since it can be disabled.
As far as sending it directly to the pl, did you read the part about me not having an control of the pl?
I do know a way to do what I need to do with Javascript, I was just hoping that I could simply pass variable values from a php to a pl without using the url as a carrier, and without the user having to click again.
Thanks for your time.
NogDog
04-02-2005, 04:44 PM
I don't know what this page is, but I can't get it to load.
Here's the code:
<?
// http.inc by nf@bigpond.net.au
// http://nf.wh3rd.net/
function http_post($server, $port, $url, $vars) {
// example:
// http_post(
// "www.fat.com",
// 80,
// "/weightloss.pl",
// array("name" => "obese bob", "age" => "20")
// );
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)";
$urlencoded = "";
while (list($key,$value) = each($vars))
$urlencoded.= urlencode($key) . "=" . urlencode($value) . "&";
$urlencoded = substr($urlencoded,0,-1);
$content_length = strlen($urlencoded);
$headers = "POST $url HTTP/1.1
Accept: */*
Accept-Language: en-au
Content-Type: application/x-www-form-urlencoded
User-Agent: $user_agent
Host: $server
Connection: Keep-Alive
Cache-Control: no-cache
Content-Length: $content_length
";
$fp = fsockopen($server, $port, $errno, $errstr);
if (!$fp) {
return false;
}
fputs($fp, $headers);
fputs($fp, $urlencoded);
$ret = "";
while (!feof($fp))
$ret.= fgets($fp, 1024);
fclose($fp);
return $ret;
}
?>
luckyluk
04-02-2005, 06:11 PM
Thanks NogDog. I'll give it a try.