Results 1 to 5 of 5

Thread: XML and POST from external server

  1. #1
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default XML and POST from external server

    hi,

    I have a script that retrieves XML via POST which is working fine:
    if (isset($_POST) && $_POST != null) {
    $string = $_POST["thexml"];
    }

    <html>
    <body>
    <form action="test.php" enctype="text/xml" method="POST">
    <textarea name="thexml" id="thexml" rows="5" cols="60">
    <xml>this works</xml>
    </textarea>
    <input type="submit">
    </form>

    However, external XML POST's may be sent to me, and I don't know what the variable name is for $_POST["thexml"] as they could be using $_POST["data"] or something else.

    How can I retrieve the posted information without knowing the name of the field they used to post the data? Is a field name always used?

    Thanks for your help.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    The form name will always be "thexml" in your example, not sure what you mean.
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by cleaner View Post
    However, external XML POST's may be sent to me...
    If by that you mean that people may send you POST data from their own forms/websites, I would strongly recommend against it. You should always force users to submit data to you via your own forms, in fact, you should check to verify that that is the case.

  4. #4
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Let's rephrase this question:
    Basically I have an external system posting a raw output stream to my script (after authentication of course). How can I catch everything that is posted and dump it into text files?

    $f = fopen ($file, 'w');
    foreach($_POST as $key => $value){
    fputs ($f, $value);
    }
    fclose ($f);

  5. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    As long as this
    Code:
    <textarea name="thexml" id="thexml" rows="5" cols="60">
    is always named "thexml", you can always access the data using $_POST['thexml'] . If it varies, you'd need some way of predicting it.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •