Page 1 of 2
Submitting form automatically... PHP
Posted: Fri Feb 24, 2006 7:33 pm
by ahsan
Hello bro...
I have got a prob! I want to submit a form automatically when I get notification
from my friend.
Is that possible?
The following code does work when I call the file from a browser but it is not
submitting the form if it is called by another server!
$frmMain="<form name='frmMain' action='...index.php' method='post'>";
$frmMain.="<input type='hidden' name='Body' value='Test'>";
$frmMain.="</form>";
$frmMain.="<script language=javascript>document.forms.frmMain.submit()</script>";
echo $frmMain;
Am I doing anything wrong here?
Posted: Fri Feb 24, 2006 7:42 pm
by feyd
Does the other server support running Javascript? I doubt that.
Posted: Fri Feb 24, 2006 7:51 pm
by shiznatix
have it run a cURL() script and send the post with that
hmm...
Posted: Fri Feb 24, 2006 8:07 pm
by ahsan
Well let me explain it then...
I have a Paypal account where I get notification from if someone donates on my site. Paypal calls my notification.php
along with some arguments. Then notification.php file updates my database and sends a mail back to the payer.
I just wanted to add a HTML FORM that will POST some processed data to my another PHP file. That would be verymuch
helpful for me if I could do it!
So... is there anyway to POST the form automatically? I am not very good in PHP as I just started learning... PLease
help!
Posted: Fri Feb 24, 2006 8:11 pm
by feyd
you shouldn't need to post any data to another file on your own server. Just include it calling the functions needed with the processed output from whatever notification is doing.
Ohh Sorry!
Posted: Fri Feb 24, 2006 8:17 pm
by ahsan
Oh... my mistake...
It POST data to another server's Form!
$frmMain="<form name='frmMain' action='
http://anotherServer.com' method='post'>";
$frmMain.="<input type='hidden' name='Body' value='Test'>";
$frmMain.="</form>";
$frmMain.="<script language=javascript>document.forms.frmMain.submit()</script>";
echo $frmMain;
I am just dying sorting this problem out!
Help!!!
Posted: Fri Feb 24, 2006 8:17 pm
by shiznatix
although feyd is correct, you should think about a design change, there is a way to do this:
curl()
and if you have questions with curl you can just search this forum because you will be able to find a lot of things about curl on this forum
edit: since its to another servers form then curl is going to be your best friend. read about it and learn to love it. post more questions if need be
:(
Posted: Fri Feb 24, 2006 8:29 pm
by ahsan
Bro!
my server doesn't support installing new PHP packages... I cant ever see
where the PHP files are located! I just upload my php file and it works...
Any tips!?
Posted: Fri Feb 24, 2006 9:55 pm
by nickman013
What do you mean allow install new PHP packages. cURL() is a function.
Posted: Fri Feb 24, 2006 10:12 pm
by josh
Nickman curl is a library of functions, it does have to be installed. Check the output of phpinfo(); you may already have it set up..
Posted: Fri Feb 24, 2006 11:12 pm
by shoebappa
You can do a post without curl...
Code: Select all
function post($host, $path, $data) {
$http_response = "";
$content_length = strlen($data);
$fp = fsockopen($host, 80);
fputs($fp, "post $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-Length: $content_length\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
while (!feof($fp)) {
$http_response .= fgets($fp, 28);
}
fclose($fp);
return $http_response;
}
$postdata = "?var1=" . urlencode($var1) . "&var2=" . urlencode($var2);
$http_response = post('anotherServer.com', '/path/to/script.php', $postdata);
Posted: Sat Feb 25, 2006 12:20 am
by nickman013
Oh I didnt know lol, woops. I thought it was just a regular PHP function.
Posted: Sat Feb 25, 2006 12:14 pm
by MinDFreeZ
shoeboppa:
using that function, would this be proper format?
Code: Select all
$postdata = "&email=" . urlencode($email) . "&password=" . urlencode($password) . "&MyToken=" . urlencode($MyToken);
$http_response = post('http://login.myspace.com/', 'index.cfm?fuseaction=login.process', $postdata);
(the variables are defined in the script earlier...)
is that correct?
... first I get:
Warning: fsockopen(): unable to connect to
http://login.myspace.com/:80 in...
then fputs(): supplied argument is not a valid stream resource in...
but that's probably because of the 1st one...
Posted: Sat Feb 25, 2006 12:56 pm
by nickman013
If you are trying to acces MySpace and it is blocked you can access it from a proxy server.
http://www.proxyguy.com
http://www.proxyfoxy.com
Posted: Sat Feb 25, 2006 2:06 pm
by MinDFreeZ
haha, "The URL is:
http://www.proxyguy.com/nph-proxy.cgi/0 ... roxy/start
The category of this URL is:Proxy Avoidance"
the proxies are blocked too.. i have no problem with getting to pages i want to..... I just want to manually submit and login to myspace (not from work, from home).. for.. other reasons.