php http_post question

Hi
   i have a php form with about 10 input fields...what i need to happen is when th user clicks submit, it needs to post the variables to a remote web server running php too where they have pretty much the same form on the remote server. So i need to post the variables that will automatically get processed on the remote server. Can someone show me ho o do this..code snippet will be great...
hegde123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

red010knightCommented:
Are you trying to create a macro form submission or something of that variety? Because that is what it sounds like.

As to how to do it... You need to know is to create a page with:
<?php
header(location: "www.gohere.com/fillThisForm.php");
?>

And your done;-)
This way their are not 30 sites trying to use the same form;-)

Hope this helps,
Red010Knight
0
hegde123Author Commented:
i basically need to know how to do a http_post from a  PHP form to a remote server , how to login and send the variables etc etc
0
red010knightCommented:
First off Forms are not PHP, the pages that process the forms give you PHP code. But Forms in general are strictly HTML and enhanced through use of CSS, Javascript and other clientside scripting.

As for logging in to a remote server - do you:
a>Have a username?
b>Have a password?
c>know the files on the remote server to call in order to have them process your data?
d>know the variable names that the remote host is expecting?
e>have permission of the remote hosts to do what you ask?

f> have the remote interest in closing any of your open questions? Currently you have 8 open. Until you have reduced the number of those questions down considerably by either, 1>going to the customer support forum and asking for something to be done about the question- whether it is to delete or something special or  2>accepting answers so that they can be closed.


You will get no more help from me and likely no one else either.

Red010Knight

PS if you answered No to any of the above questions - seek a solution/resolution to them before making another post - Thanks!!
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

hegde123Author Commented:
a>Have a username?--yes i have a username
b>Have a password?--yes
c>know the files on the remote server to call in order to have them process your data?---yes
d>know the variable names that the remote host is expecting?---yes
e>have permission of the remote hosts to do what you ask?--yes

f> i've graded all the questions..the reason it was open was cause most of them did'nt answer my questions 100% and i got the answers elsewhere..i've still graded them anyway for the good feedback...

coming back to the question, what i'm after is the code or a resource that allows me the follwoing...post variables from my php form to the remote server with the login, pasword etc using the HTTP POST method when the user fills up the input fields on my server and hits submit..thanks in advance..i'm running php 4.3.2 on windows 2000...thanks
0
KaritzCommented:
There are nice tutorials on how to start working with forms on the net. Please look at them and should there be any problem contact me.

http://www.evolt.org/article/User_Friendly_Forms_in_PHP/20/60144/
http://codewalkers.com/tutorials.php?show=12

KaRitZ
0
lozlozCommented:
how does the login system work on the remote system? to post to another server you simply need the form to point to the server's processing script with the action as their file e.g. <form method="POST" action="http://www.server.com/folder/file.php">

loz
0
red010knightCommented:
Then you should not have a problem just having the form be posted to the remote server and let their processing scripts handle the data.

As PHP has no real say in how things are posted. It only affects pages that are generated.

If you have to have a username and password to post data - can you tell us how the remote server is handling those? Via cookies/sessions/post/get data?

If via post - get a generic username and password and set them up in
<input type="hidden" name="username" value="blah">
<input type="hidden" name="password" value="blah">

if via get then you will need to have it :
<form method="POST" action="http://www.server.com/folder/file.php?username=blah&password=blah">

if via sessions someone else will need to help you as I have not bothered with them.

if via cookies you will need to set a cookie on your forms page
www.php.net and search for setcookie() and that should get you going.

Hope that helps,
Red010Knight
0
hegde123Author Commented:
so where does the http_post class method come i?..is that the same as the form post method....apologies for being ignorant but i'm not sure what the http_post method does..
0
lozlozCommented:
<form method="POST"> means send the data over an HTTP POST connection so yes you should use that

loz
0
hegde123Author Commented:
and with respect to passing the variables, do we pass the variables the same way as we pass when we post variables from one form to another?
0
lozlozCommented:
yes everything's exactly the same as if it were on your server, just the action points to the remote script

loz
0
hegde123Author Commented:
how do these 2 sites below differ from the normal form post method?...are they doing the same?

http://www.phpbuilder.com/mail/php-general/2003022/1806.php

http://docs.akbkhome.com/pearcvs/HTTP_Post.html
0
lozlozCommented:
the only difference is that they're not letting the user enter data into the form before sending off the data - the post data is sent by a script with the post data defined by the script writer whereas the post data is sent from user input using a form

loz
0
hegde123Author Commented:
how do we handle logging in to the remore server though?
0
red010knightCommented:
How is the remote server admin handleing login??? If you do know how he is handling logins, please post that here so that we can addequately answer your question.

Is it with PHP, MYSQL, or something else??
I believe I addressed several ways of doing it in my previous comment. If none of them are working, you will need to contact the remote server admin and ask what it is you need to do. Because there are likely security measures in place that prevent any joe smoh from doing what you are asking.

Red010Knight
0
hegde123Author Commented:
basically what they've said is that we dont need to login etc ...all i need to do is the post the variables to the form running php on the remote server...i'm in the process of trying that now..once i post the variables, how do i get it automatically processed as soon as i post ?....what i mean is have whatever action is performed on the remote server when the submit button is hit on their server?
0
lozlozCommented:
well if you send it to the right URL, there will be some sort of check there by the script for a variable which will set off the processing, presumably.. something like:

if($_POST["submit"]) {
  # form is submitted, process it
}

loz
0
red010knightCommented:
First off,
Do not try posting to their form, look at the forms action ... then use that as your form action and make sure the variable names are the same.

If their form action is something like "../IAm/here.php" then add the rest of the URL in the browser to the spot where .. is and it should work with no problem.

Red010Knight
0
hegde123Author Commented:
how do i run something on hitting submit on my server too?..what i mean is when i hit submit, the forms action will point to the action of the remote server..at the same time , i'd like to run something on our database too..is that possible
0
red010knightCommented:
<form action="submit to here" onSubmit="do this">
</form>
Very simple
0
hegde123Author Commented:
but the action part would be posting to the remote server when submit is hit...

<form name="form1" method="post" action="remote_server.php?UID=06a4f23c5b8464a3a7259c617294bd47">..

at the same time i wanna make it run something on the local server..

basically i dont want the form page to redirect to the remote server page on submit..but just post the variables and get them processed on the remote server and redirect to the local server and run a process locally..

0
red010knightCommented:
Look into javascript.

You wouldn't have an action. Just a your submit button having an 'onClick' attribute.
The attribute would then need to call a javascript function that sends the variables out for you while nothing changes on the page you are on.

Basically just having <form name="blah">
with a button <input type="button" value="Submit" name="submit" onclick="javascript:sendStuff();">

That should do what you want.

Red010Knight
0
hegde123Author Commented:
so in the send stuff, i can run  a process that would post the form variables to the remote server and at the same time run  a process on my database...for example on submit what i want to do it post the variables to the remote server and then insert the  variables into the mysql database on my local server....

i'm not sure how to do a post in javascript though..just know how to do it using the normal form action posting....thanks
0
hegde123Author Commented:
i understand that i can do something like this:

<form method="post" name="form1" action="http://remoteserver" onsubmit="submitcheck();">

but i'm still not sure that once the posting is don to the remote server, how do i run a database insert on my server...obviously cant be done within the submit check as its javascript and only runs on the client side...
0
red010knightCommented:
Actually, the best way to do what you want. Is best done using a post to your own processing file. Where you right to your database, and then take those variables and send it to the remote server. That would be my more favorable idea.

Now my current question is to verify things, is this your intent:
                                                  {remote server
Form page -> Processing page<    {database input    
                                                  {form page  ----> repeat if desired

The processing page would basically have three functions - remote server posting, local server input, and refresh the Form page with whatever updated values you need it to have...

Is this right? If it does what you want - that would be the recommended way to go about it.

Red010Knight

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hegde123Author Commented:
yep..thats exactly what i want to do...how do i go about that..i know how to process forms locally, redirect the page with the updated values etc..manipulate and write to the database etc..but posting the variables from the database to the remote server is what i'm not sure ....so just what you said...remote server posting, local server input, and refresh the Form page with whatever updated values i need it to have..
0
lozlozCommented:
hi,

you probably want to use something like this function:

http://www.faqts.com/knowledge_base/view.phtml/aid/12039/fid/51

basically you have the form submit to a local page which does the database input and displays the form again if you want. it also uses fsock functions to connect to a remote server and post the data there as a normal form would

cheers,

loz
0
hegde123Author Commented:
doe this work on windows?
0
lozlozCommented:
ought to. there's a comment at http://uk.php.net/fsockopen which seems to suggest you might need to replace \r with \x0D\x0A, that's the only thing relating to windows, are you having problems?

loz
0
hegde123Author Commented:
yep..it just seem to hang when i try to call that function passing the parameters
0
hegde123Author Commented:
i've tried the XoD change to..and it just hangs..

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.1\x0D\x0A");
                         fputs($fp, "Host: $host\x0D\x0A");
                         if ($useragent) {
                           fputs($fp, "User-Agent: MSIE\x0D\x0A");
                         }
                         if ($method == 'POST') {
                           fputs($fp,"Content-type: application/x-www-form-urlencoded\x0D\x0A");
                           fputs($fp, "Content-length: " . strlen($data) . "\x0D\x0A");
                         }
                         fputs($fp, "Connection: close\x0D\x0Ax0D\x0A");
                         if ($method == 'POST') {
                             fputs($fp, $data);
                         }

                         while (!feof($fp)) {
                             $buf .= fgets($fp,128);
                         }
                         fclose($fp);
                         return $buf;
                     }



0
lozlozCommented:
how are you calling the function?

loz
0
hegde123Author Commented:
sendToHost('http://192.168.8.102','post','/hprice.php',
               'delete=Y&rid1=921');


within a php file
0
lozlozCommented:
i don't think it'll work but try taking the http:// off the front of the first argument for sendtohost

can i see the complex file where this functino is executed?

loz
0
hegde123Author Commented:
if ($delete == "Y")

    {
     $code = load_php_include ('33'); eval($code);
include "oracle_connect.inc.php";

    $sql1 = "DELETE FROM sub.handset_price WHERE ID='$rid1'";

         $ora_sql = OCIParse($oracle_conn,$sql1);
         ociexecute($ora_sql);

include "oracle_disconnect.inc.php";

     $code = load_php_include('13'); eval($code);
     exit;
    }


0
lozlozCommented:
sorry i meant complete file.. so any includes that are relating to it too

loz
0
hegde123Author Commented:
ACTUALLY I'VE CHANGED IT AS I DONT NEED THE INCLUDES AT THE TOP....as they're just for creating the headers..i've included on einclude though at the bottom..

if ($delete == "Y")

    {
include "ora.inc.php";

    $sql1 = "BEGIN DELETE FROM sub.handset_price; COMMIT; END;";

         $ora_sql = OCIParse($oracle_conn,$sql1);
         ociexecute($ora_sql);

include "oracle_disconnect.inc.php";

     $code = load_php_include('13'); eval($code);
     exit;
    }




includes:

if ($authed == "Y")
    {
     update_session ($session_id,'Y',$email,$clerk_id,$sexp);
    }

     echo "<br></td>";

     echo "</table>
               </center>";

     echo "</td>";
     echo "</table>
               </center>";

         echo "</td>";
         echo "</table>
               </center>";

if (!isset($redirect))
    {
     echo footer;
    }

echo "</body>
      </html>";
     
//include_once "mysql_unconnect.inc.php";

//include "oracle_disconnect.inc.php";
exit;


function update_session ($session_id,$authed,$email,$id,$sexp)
    {
     if ($authed == "Y")
         {
          $sql = "UPDATE session
                  SET email = '$email',
                      clerk_id = '$id',
                      authed = '$authed',
                      date_expired = DATE_ADD(NOW(),INTERVAL '$sexp' MINUTE)
                  WHERE session_id = '$session_id'";

          mysql_query($sql) or die ("Couldn't execute SQL query - extend session");
         }
    }

0
hegde123Author Commented:
actually when i removed the http, it doesnt hang anymore..but still doesnt do the delete
0
lozlozCommented:
where's $delete coming from? is register_globals on? and wheres the sendtohost function/execution of it?

loz
0
hegde123Author Commented:
yep..$delete is the subsection withinn the php file...so when i say /hprice.php?delete=Y it gores to the section within the php file where $delete=Y and executes the deletion part..

the senttohost function is within another php file
0
lozlozCommented:
if register_globals is off, you'll need to use if ($_GET["delete"] == "Y") unless you're using a php version before 4.1.0, in which case it needs to be $HTTP_GET_VARS["delete"]. the same goes for other variables from the url (i assume $authed is one so it should become $_GET["authed"])

loz
0
hegde123Author Commented:
register globals are on....also from from to from it works fine...so on our intranet if i execute the hprice.php?delete=Y, it executes sucessfully..
0
hegde123Author Commented:
what is the simplest way to test if the function is working..?...
0
lozlozCommented:
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.1\x0D\x0A");
                      fputs($fp, "Host: $host\x0D\x0A");
                      if ($useragent) {
                        fputs($fp, "User-Agent: MSIE\x0D\x0A");
                      }
                      if ($method == 'POST') {
                        fputs($fp,"Content-type: application/x-www-form-urlencoded\x0D\x0A");
                        fputs($fp, "Content-length: " . strlen($data) . "\x0D\x0A");
                      }
                      fputs($fp, "Connection: close\x0D\x0Ax0D\x0A");
                      if ($method == 'POST') {
                          fputs($fp, $data);
                      }

                      while (!feof($fp)) {
                          $buf .= fgets($fp,128);
                      }
                      fclose($fp);
                      return $buf;
                  }

$socket = sendToHost('192.168.8.102','post','/hprice.php','delete=Y&rid1=921');
if($socket) {
  print $socket;
} else {
  print "failed";
}

i think..

loz
0
hegde123Author Commented:
this doesnt seem to be working..is this the only way i can do secure socket or https connection programming?
0
lozlozCommented:
whoops musta missed that reply

sorry i can't help you with that sorta stuff - did you get this working?

cheers,

loz
0
hegde123Author Commented:
yep..its working now..i've split the points betwen you and redknight....it just needed ssl support..basiclally php 4.3.4 doesnt have openssl support..its buggy..i've got php 5 runninbg and its working fine now. Thanks for yor help..btw i have another question that i've just posted..help would be appreciated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.