Posting to another URL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • djones5@citgo.com

    Posting to another URL

    Any help from the gods is appreciated.

    I can cut and paste the following into my browser URL address and have
    the script execute no problem:



    the domain is another site. How can I run a php script on my server
    that will essentially post the above, but within my php script?

    As always, help from the gods is appreciated.

    DJ

  • japh

    #2
    Re: Posting to another URL

    look up documentation on curl. I'm not quite sure what yo u are trying
    to do, but here is a sample that sends data to a payment gateway and
    awaits a response:
    note: not all servers support curl.

    // your data - separated with &
    $fields = "amount=10.00&o rderid=123456";
    $url = "https://domain.com/where_you_want_ to_post.asp";

    $ch = curl_init($url) ;
    curl_setopt($ch , CURLOPT_HEADER, 0);
    curl_setopt($ch , CURLOPT_RETURNT RANSFER, 1);
    curl_setopt($ch , CURLOPT_POSTFIE LDS, $fields);
    $response = curl_exec($ch);
    curl_close ($ch);


    // after you post your data, the server response will be stored in the
    $response variable

    Comment

    • ggg@gg.com

      #3
      Re: Posting to another URL

      If you don't have CURL installed on your server, you can make a socket
      call with the POST method:



      // postToHost.php
      // Sample of posting to a local or remote server
      // Written by Rasmus Lerdorf
      // buy his book published Mar 2002
      // ---------------------------------------------
      //Use fsockopen to send the data:
      $host = "your.host" ;
      $port = 80;
      $postdata = "field1=value1& field2=value2&f ield3=value3";
      if ($sp = fsockopen($host , $port)) {
      fputs($sp,"POST /path/to/script.php HTTP/1.0\n");
      fputs($sp,"Host : $host\n");
      fputs($sp,"Cont ent-type: application/x-www-form-urlencoded\n");
      fputs($sp,"Cont ent-length: ".strlen($postd ata)."\n");
      fputs($sp,"Conn ection: close\n\n");
      fputs($sp,$post data);
      fclose($sp);
      }



      In article <1107896920.243 522.150580@f14g 2000cwb.googleg roups.com>,
      djones5@citgo.c om says...[color=blue]
      > Any help from the gods is appreciated.
      >
      > I can cut and paste the following into my browser URL address and have
      > the script execute no problem:
      >
      > http://subdomain.domain.com/log?amou...orderid=123456
      >
      > the domain is another site. How can I run a php script on my server
      > that will essentially post the above, but within my php script?
      >
      > As always, help from the gods is appreciated.
      >
      > DJ
      >
      >[/color]

      Comment

      • Chung Leong

        #4
        Re: Posting to another URL

        <djones5@citgo. com> wrote in message
        news:1107896920 .243522.150580@ f14g2000cwb.goo glegroups.com.. .[color=blue]
        > Any help from the gods is appreciated.
        >
        > I can cut and paste the following into my browser URL address and have
        > the script execute no problem:
        >
        > http://subdomain.domain.com/log?amou...orderid=123456
        >
        > the domain is another site. How can I run a php script on my server
        > that will essentially post the above, but within my php script?
        >
        > As always, help from the gods is appreciated.
        >[/color]

        I don't know why people keep suggesting CURL or socket when there is a
        standard way to do a post in PHP: a stream context.

        See this thread:




        Comment

        • Geoff Berrow

          #5
          Re: Posting to another URL

          I noticed that Message-ID:
          <1107896920.243 522.150580@f14g 2000cwb.googleg roups.com> from
          djones5@citgo.c om contained the following:
          [color=blue]
          >As always, help from the gods is appreciated.[/color]

          Saints, not gods. :-)

          --
          Geoff Berrow (put thecat out to email)
          It's only Usenet, no one dies.
          My opinions, not the committee's, mine.
          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

          Comment

          • ggg@gg.com

            #6
            Re: Posting to another URL

            [color=blue]
            >
            > I don't know why people keep suggesting CURL or socket when there is a
            > standard way to do a post in PHP: a stream context.
            >
            > See this thread:
            >
            > http://groups-beta.google.com/group/...9b5eb9e7a6275e
            >[/color]

            I know why. It's because streams is a post 4.3 feature -- I didn't know
            about it. I ought to keep up with things.

            Comment

            Working...