Submitting form automatically... PHP

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

ahsan
Forum Newbie
Posts: 6
Joined: Fri Feb 24, 2006 7:22 pm

Submitting form automatically... PHP

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Does the other server support running Javascript? I doubt that.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

have it run a cURL() script and send the post with that
ahsan
Forum Newbie
Posts: 6
Joined: Fri Feb 24, 2006 7:22 pm

hmm...

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
ahsan
Forum Newbie
Posts: 6
Joined: Fri Feb 24, 2006 7:22 pm

Ohh Sorry!

Post 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! 8O

Help!!!
Last edited by ahsan on Fri Feb 24, 2006 8:19 pm, edited 1 time in total.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
ahsan
Forum Newbie
Posts: 6
Joined: Fri Feb 24, 2006 7:22 pm

:(

Post 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!?
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

What do you mean allow install new PHP packages. cURL() is a function.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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..
User avatar
shoebappa
Forum Contributor
Posts: 158
Joined: Mon Jul 11, 2005 9:14 pm
Location: Norfolk, VA

Post 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);
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Oh I didnt know lol, woops. I thought it was just a regular PHP function.
MinDFreeZ
Forum Commoner
Posts: 58
Joined: Tue Feb 14, 2006 12:28 pm
Location: Lake Mary, FL

Post 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...
Last edited by MinDFreeZ on Sat Feb 25, 2006 11:53 pm, edited 2 times in total.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

If you are trying to acces MySpace and it is blocked you can access it from a proxy server.

:arrow: http://www.proxyguy.com
:arrow: http://www.proxyfoxy.com
MinDFreeZ
Forum Commoner
Posts: 58
Joined: Tue Feb 14, 2006 12:28 pm
Location: Lake Mary, FL

Post 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.
Post Reply