How to pass XML requests to a PHP script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Gaunt

    How to pass XML requests to a PHP script

    My site is based on XML templates and uses a PHP script to turn them
    into XHTML. The script use the expat parser functions and works just
    fine. The XSLT extensions are not enabled on the server.

    At the moment I am passing requests for the XML files to the script by
    setting up .xml as a PHP file using AddType and then using a
    mod_rewrite rule to ensure that the request gets handled by the script
    (don't laugh!). This is all set up in .htaccess which is all I have
    access to.

    It's worked fine like this for the past year or so but is, I guess, not
    the best way to do it. I'm guessing that there's probably some way to
    do this using AddHandler and Action directives (or something) which
    would be more 'correct'.

    What's the best way to achieve this. Server is virtual running on
    Apache 1.3.27 (Linux).

    --
    Pete
    ====
    *** Email is pete -at- dawnsun -dot- net
  • Chung Leong

    #2
    Re: How to pass XML requests to a PHP script

    Something like http://www.example.com/transform.php/filename.xml, perhaps?
    The PHP script will get the name of the XML file in $_SERVER['PATH_INFO'].

    Uzytkownik "Peter Gaunt" <pete@email.in. my.sig> napisal w wiadomosci
    news:1602200409 17076269%pete@e mail.in.my.sig. ..[color=blue]
    > My site is based on XML templates and uses a PHP script to turn them
    > into XHTML. The script use the expat parser functions and works just
    > fine. The XSLT extensions are not enabled on the server.
    >
    > At the moment I am passing requests for the XML files to the script by
    > setting up .xml as a PHP file using AddType and then using a
    > mod_rewrite rule to ensure that the request gets handled by the script
    > (don't laugh!). This is all set up in .htaccess which is all I have
    > access to.
    >
    > It's worked fine like this for the past year or so but is, I guess, not
    > the best way to do it. I'm guessing that there's probably some way to
    > do this using AddHandler and Action directives (or something) which
    > would be more 'correct'.
    >
    > What's the best way to achieve this. Server is virtual running on
    > Apache 1.3.27 (Linux).
    >
    > --
    > Pete
    > ====
    > *** Email is pete -at- dawnsun -dot- net[/color]


    Comment

    • Ash Argent-Katwala

      #3
      Re: How to pass XML requests to a PHP script

      On Mon, 16 Feb 2004, Peter Gaunt wrote:[color=blue]
      >At the moment I am passing requests for the XML files to the script by
      >setting up .xml as a PHP file using AddType and then using a
      >mod_rewrite rule to ensure that the request gets handled by the script
      >(don't laugh!). This is all set up in .htaccess which is all I have
      >access to.[/color]

      I think the AddType for xml is a red herring. If your mod_rewrite rules
      terminate with an internal location that ends .php (or whatever extension
      you've already got set up to handle PHP) then the URL the outside world ever
      sees can end with whatever you like.

      e.g.
      RewriteEngine On
      RewriteRule ^/images/([^/]+)\.jpg /serve_image.php ?filename=$1 [L]

      will work just fine.

      I often do:

      RewriteEngine On
      RewriteRule ^/internal/ - [F]

      then map the odd URLs onto scripts in an 'internal' directory, just to be
      damn sure no-one will call them from outside. It pinches a bit of the
      namespace for external URLs, but it's nice and explicit. It also means you
      can be pretty sure that something that's a numeric parameter really is, just
      in the RewriteRules.

      --
      ash
      a-k
      .... People who deal with bits should expect to get bitten.

      Comment

      • Peter Gaunt

        #4
        Re: How to pass XML requests to a PHP script

        In article <Pine.LNX.4.58. 0402171047040.2 2786@gauss.doc. ic.ac.uk>, Ash
        Argent-Katwala <ash@videdot.co m> wrote:
        [color=blue]
        > On Mon, 16 Feb 2004, Peter Gaunt wrote:[color=green]
        > >At the moment I am passing requests for the XML files to the script by
        > >setting up .xml as a PHP file using AddType and then using a
        > >mod_rewrite rule to ensure that the request gets handled by the script
        > >(don't laugh!). This is all set up in .htaccess which is all I have
        > >access to.[/color]
        >
        > I think the AddType for xml is a red herring.[/color]

        Yes, you're right it is. It's a hang over from an earlier attempt to do
        this. What I'm actually trying to do is to avoid using mod_rewrite for
        this at all though and having looked through the Apache docs properly
        this time I've found the answer was staring me in the face all along. I
        just use something like:

        Action add-xmlstuff /xml_handler.php
        AddHandler add-xmlstuff .xml

        don't I? Then all requests for .xml files get passed to xml_handler.php
        and everything's hunk dory. I have to play around with PATH_TRANSLATED
        a bit to extract some info but that's dead easy (at least on servers
        where document_root is exported to $_SERVER).

        Or am I still barking up a gum tree?

        --
        Pete
        ====
        *** Email is pete -at- dawnsun -dot- net

        Comment

        Working...