PHP assistance needed - experts only please!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • betty1980
    Registered User
    • Apr 2007
    • 9

    #1

    PHP assistance needed - experts only please!

    Hi,
    My name is Betty and I need some help.

    I want to send a data string from a php file on 1 server to another php file on another server.

    example:

    Server 1 / file1.php -> Server 2 / file2.php
    Server 2 / file2.php -> Server 1 / file1.php

    It's actually posting data to another file on another server and getting the result.

    Thank you,
    Betty
  • naitirps
    Confirmed User
    • May 2004
    • 761

    #2
    use curl within php to post to the other server/script
    Programmer
    ICQ 44035273 | AIM spritwork | Email spritian at spritian dot com

    Comment

    • betty1980
      Registered User
      • Apr 2007
      • 9

      #3
      I am afraid to use curl since some servers might not support it.

      Comment

      • Yahook
        Confirmed User
        • May 2002
        • 840

        #4
        http://sourceforge.net/projects/nusoap/

        Comment

        • k0nr4d
          Confirmed User
          • Aug 2006
          • 9231

          #5
          most servers have curl installed. If you dont wanna use the php extensions, use curl from cli using exec();
          Mechanical Bunny Media
          Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development

          Comment

          • adultseo
            Confirmed User
            • Jun 2005
            • 365

            #6
            Hi!

            The most easy way is this:

            Server 1:
            Code:
            <?php
            
            $data = array(array(1,3,4,5),1,2,3,4,array(array(10,11,12),'test'));
            $output = var_export($data,true);
            
            print $output;
            
            ?>
            Server 2:
            Code:
            <?php
            
            $data_text = file_get_contents('url/to/server_1.php');
            eval('$data = '.$data_text.';');
            
            print_r($data);
            
            ?>
            The key to get ranked one in Google is to provide the best.

            Comment

            • edgeprod
              Permanently Gone
              • Mar 2004
              • 10019

              #7
              "Experts only" for simple questions, please!



              I'm not making fun of you, it just made me chuckle.

              Comment

              • betty1980
                Registered User
                • Apr 2007
                • 9

                #8
                Originally posted by adultseo
                Hi!

                The most easy way is this:

                Server 1:
                Code:
                <?php
                
                $data = array(array(1,3,4,5),1,2,3,4,array(array(10,11,12),'test'));
                $output = var_export($data,true);
                
                print $output;
                
                ?>
                Server 2:
                Code:
                <?php
                
                $data_text = file_get_contents('url/to/server_1.php');
                eval('$data = '.$data_text.';');
                
                print_r($data);
                
                ?>

                Thank you, but I don't understand.
                I need to send data to the other server and accourding to this data perform an action. I didn't mean to just read the data as is on the other server.

                Comment

                • k0nr4d
                  Confirmed User
                  • Aug 2006
                  • 9231

                  #9
                  wait a second, a girl who codes?!??
                  hot.
                  Mechanical Bunny Media
                  Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development

                  Comment

                  • Zoose
                    Confirmed User
                    • Aug 2006
                    • 268

                    #10
                    Is this data from a database? If so just give the server that needs the data proper access privileges in MySQL and vice versa. Depending on the data you might even be able to do it with fopen and query strings. It's hard to give you advice without knowing the exact situation.

                    Comment

                    • adultseo
                      Confirmed User
                      • Jun 2005
                      • 365

                      #11
                      Originally posted by betty1980
                      Thank you, but I don't understand.
                      I need to send data to the other server and accourding to this data perform an action. I didn't mean to just read the data as is on the other server.
                      what kind of data are you trying to submit?

                      You can use a regulare header post configuration, Curl is nothing more then a automated system for regular header commands. It can be done manually aswell.
                      The key to get ranked one in Google is to provide the best.

                      Comment

                      • betty1980
                        Registered User
                        • Apr 2007
                        • 9

                        #12
                        I don't want to give server1 access to the database.

                        Comment

                        • betty1980
                          Registered User
                          • Apr 2007
                          • 9

                          #13
                          Originally posted by adultseo
                          what kind of data are you trying to submit?

                          You can use a regulare header post configuration, Curl is nothing more then a automated system for regular header commands. It can be done manually aswell.
                          The data is a text string.

                          Comment

                          • k0nr4d
                            Confirmed User
                            • Aug 2006
                            • 9231

                            #14
                            <? exec("curl -d \"foo=bar&bar=foo\" \"urltootherfile\""); ?>
                            Mechanical Bunny Media
                            Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development

                            Comment

                            • betty1980
                              Registered User
                              • Apr 2007
                              • 9

                              #15
                              Originally posted by adultseo
                              what kind of data are you trying to submit?

                              You can use a regulare header post configuration, Curl is nothing more then a automated system for regular header commands. It can be done manually aswell.
                              Can you send me an example?

                              Comment

                              • betty1980
                                Registered User
                                • Apr 2007
                                • 9

                                #16
                                Originally posted by k0nr4d
                                <? exec("curl -d \"foo=bar&bar=foo\" \"urltootherfile\""); ?>
                                2 questions:

                                1. Do you know if there is a limit to the length of the string. foo=$report, what is the maximum length of $report ?
                                2. How do I get the returned value?

                                Comment

                                • sarettah
                                  see you later, I'm gone
                                  • Oct 2002
                                  • 14297

                                  #17
                                  Originally posted by edgeprod
                                  "Experts only" for simple questions, please!



                                  I'm not making fun of you, it just made me chuckle.
                                  Yeah, that was how I looked at it too. I thinks she is making it harder than it actually is.

                                  But what do I know, I'm just a pert not an ex-pert.

                                  All cookies cleared!

                                  Comment

                                  • sarettah
                                    see you later, I'm gone
                                    • Oct 2002
                                    • 14297

                                    #18
                                    Originally posted by betty1980
                                    Thank you, but I don't understand.
                                    I need to send data to the other server and accourding to this data perform an action. I didn't mean to just read the data as is on the other server.
                                    He was performing an action. Printing it. You could substitute any particular action you wanted to perform on the data where he had the print statement.
                                    All cookies cleared!

                                    Comment

                                    • adultseo
                                      Confirmed User
                                      • Jun 2005
                                      • 365

                                      #19
                                      Code:
                                      function HTTPS_Post($URL, $dat, $referrer="")
                                      {
                                      // parsing the given URL
                                      $URL_Info=parse_url($URL);
                                      
                                      // Building referrer
                                      if($referrer=="") // if not given use this script as referrer
                                      $referrer=$_SERVER["SCRIPT_URI"];
                                      
                                      // making string from $data
                                      foreach($dat as $key=>$value) $values[]="$key=".urlencode($value);
                                      $data_string=implode("&",$values);
                                      
                                      // Find out which port is needed - if not given use standard (=443)
                                      if(!isset($URL_Info["port"])) $URL_Info["port"] = 80;
                                      
                                      // building POST-request:
                                      $request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
                                      $request.="Host: ".$URL_Info["host"]."\n";
                                      $request.="Referer: $referer\n";
                                      $request.="Content-type: application/x-www-form-urlencoded\n";
                                      $request.="Content-length: ".strlen($data_string)."\n";
                                      $request.="Connection: close\n";
                                      $request.="\n";
                                      $request.=$data_string."\n";
                                      
                                      $result = '';
                                      if ($fp = fsockopen("ssl://" . $URL_Info["host"], $URL_Info["port"],
                                      $errno, $errstr, 2.0))
                                      {
                                      fputs($fp, $request);
                                      $started = time;
                                      while((!feof($fp)) and ((time - $started) < 5))
                                      {
                                      $result .= @fgets($fp, 128);
                                      }
                                      fclose($fp);
                                      }
                                      return $result;
                                      }
                                      The key to get ranked one in Google is to provide the best.

                                      Comment

                                      • sarettah
                                        see you later, I'm gone
                                        • Oct 2002
                                        • 14297

                                        #20
                                        Ok, several people have asked you more more info and you aren't really offering anything up, so I will offer up what I think is the simplest solution, however, it would help to know what you are actually trying to do.

                                        This is a 2 script solution. script1 is on server1, script2 is on server2.

                                        Script1 is kicked off somehow (depending on what you are doing) either a call from a browser, a post action in a form, a cron job, whatever.

                                        script1 collects or retrieves data (whatever your initial data source is)
                                        script1 writes the data to a file on server1 (or could write it via ftp it to server2)
                                        script1 then does an fopen() to script2 on server2

                                        script2 opens the file created by script1 whether via fopen() to the url for the file on server1 or an fopen() to the file where it was written on server2
                                        script2 performs whatever steps are required to be performed on the data (writes it to a database, performs verification, jerks off to it, whatever)
                                        script2 returns a done message (which could be the results of the steps performed in script2).

                                        done.

                                        There are, as people have said, many different ways to skin this particular cat. It seems to me though, from watching this conversation, that you need to draw out your step by step of what you are actually trying to do.

                                        just my
                                        Last edited by sarettah; 04-18-2007, 04:54 PM.
                                        All cookies cleared!

                                        Comment

                                        • adultseo
                                          Confirmed User
                                          • Jun 2005
                                          • 365

                                          #21
                                          Code:
                                          $options = array(
                                            'http'=>array(
                                              'method'=>"POST",
                                              'header'=>
                                                "Accept-language: en\r\n".
                                                "Content-type: application/x-www-form-urlencoded\r\n",
                                              'content'=>http_build_query(array('foo'=>'bar'))
                                          ));
                                          
                                          $context = stream_context_create($options);
                                          
                                          fopen('http://www.example.com/',false,$context);
                                          The key to get ranked one in Google is to provide the best.

                                          Comment

                                          • betty1980
                                            Registered User
                                            • Apr 2007
                                            • 9

                                            #22
                                            Originally posted by adultseo
                                            Code:
                                            function HTTPS_Post($URL, $dat, $referrer="")
                                            {
                                            // parsing the given URL
                                            $URL_Info=parse_url($URL);
                                            
                                            // Building referrer
                                            if($referrer=="") // if not given use this script as referrer
                                            $referrer=$_SERVER["SCRIPT_URI"];
                                            
                                            // making string from $data
                                            foreach($dat as $key=>$value) $values[]="$key=".urlencode($value);
                                            $data_string=implode("&",$values);
                                            
                                            // Find out which port is needed - if not given use standard (=443)
                                            if(!isset($URL_Info["port"])) $URL_Info["port"] = 80;
                                            
                                            // building POST-request:
                                            $request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
                                            $request.="Host: ".$URL_Info["host"]."\n";
                                            $request.="Referer: $referer\n";
                                            $request.="Content-type: application/x-www-form-urlencoded\n";
                                            $request.="Content-length: ".strlen($data_string)."\n";
                                            $request.="Connection: close\n";
                                            $request.="\n";
                                            $request.=$data_string."\n";
                                            
                                            $result = '';
                                            if ($fp = fsockopen("ssl://" . $URL_Info["host"], $URL_Info["port"],
                                            $errno, $errstr, 2.0))
                                            {
                                            fputs($fp, $request);
                                            $started = time;
                                            while((!feof($fp)) and ((time - $started) < 5))
                                            {
                                            $result .= @fgets($fp, 128);
                                            }
                                            fclose($fp);
                                            }
                                            return $result;
                                            }

                                            Thank you,
                                            Yours script works great and does exactly what I need.

                                            Comment

                                            • betty1980
                                              Registered User
                                              • Apr 2007
                                              • 9

                                              #23
                                              I would like to thank you all for your help. I appreciate it.
                                              For all of you that didn't understand me for asking experts help, I didn't mean to insult you, but before I have tried to post this question on another form and got answers that didn't help much, so I though I would need an expert for that.
                                              Thanks again,

                                              Love,
                                              Betty.

                                              Comment

                                              • edgeprod
                                                Permanently Gone
                                                • Mar 2004
                                                • 10019

                                                #24
                                                Originally posted by betty1980
                                                Thank you,
                                                Yours script works great and does exactly what I need.
                                                It's not his script. It's from a script site.

                                                Comment

                                                • borked
                                                  Totally Borked
                                                  • Feb 2005
                                                  • 6284

                                                  #25
                                                  Originally posted by betty1980
                                                  Thank you,
                                                  Yours script works great and does exactly what I need.
                                                  No idea what you're using it for, but you may well want to think about sanitising the post vars on server 2, or passing a key in the post from server 1...

                                                  For coding work - hit me up on andy // borkedcoder // com
                                                  (consider figuring out the email as test #1)



                                                  All models are wrong, but some are useful. George E.P. Box. p202

                                                  Comment

                                                  Working...