$HTTP_SERVER_VARS['SCRIPT_FILENAME'] - getting all GET vars too?

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

    #1

    $HTTP_SERVER_VARS['SCRIPT_FILENAME'] - getting all GET vars too?

    Hi,

    I am using $HTTP_SERVER_VA RS['SCRIPT_FILENAM E'] to get the name of the
    current web page. How do I also get the GET variables using PHP as a
    complete string. For example:

    '?first=12&seco nd=value&third= 2.99'

    As I dont know what the variables may I cant simply use $_GET. Ideally
    something like FOR EACH $_GET to generate the GET part of the url. Any
    ideas? Cheers

    Burnsy
  • Andy Hassall

    #2
    Re: $HTTP_SERVER_VA RS['SCRIPT_FILENAM E'] - getting all GET vars too?

    On 5 Dec 2004 07:25:00 -0800, bissatch@yahoo. co.uk (mr_burns) wrote:
    [color=blue]
    >I am using $HTTP_SERVER_VA RS['SCRIPT_FILENAM E'][/color]

    $_SERVER would be preferred, but it's the same info.
    [color=blue]
    >to get the name of the
    >current web page. How do I also get the GET variables using PHP as a
    >complete string. For example:
    >
    >'?first=12&sec ond=value&third =2.99'[/color]

    Look at $_SERVER['QUERY_STRING']

    phpinfo() is useful for dumping out all the superglobals, or you could just
    var_dump($_SERV ER) etc.; you can then see which ones may have the information
    you need.
    [color=blue]
    >As I dont know what the variables may I cant simply use $_GET. Ideally
    >something like FOR EACH $_GET to generate the GET part of the url.[/color]

    Well, yes exactly that.

    foreach ($_GET as $key => $val)

    ... same as any associative array. There could be arrays in there though which
    are treated a bit differently. It's all available in $_SERVER['QUERY_STRING'],
    but looping through $_GET may be useful if:

    (a) you want to modify/add/remove some of the values, but keep the rest
    (b) you want to change the separator, e.g. from & to ;

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Michael Fesser

      #3
      Re: $HTTP_SERVER_VA RS['SCRIPT_FILENAM E'] - getting all GET vars too?

      .oO(Andy Hassall)
      [color=blue]
      >On 5 Dec 2004 07:25:00 -0800, bissatch@yahoo. co.uk (mr_burns) wrote:
      >[color=green]
      >>I am using $HTTP_SERVER_VA RS['SCRIPT_FILENAM E'][/color]
      >
      > $_SERVER would be preferred, but it's the same info.[/color]

      Same info, but not the same scope. $_SERVER is superglobal, the old
      $HTTP_* arrays are not.
      [color=blue]
      >but looping through $_GET may be useful if:
      >
      >(a) you want to modify/add/remove some of the values, but keep the rest
      >(b) you want to change the separator, e.g. from & to ;[/color]

      This can also be done with modifying 'arg_separator. input' if possible.

      Micha

      Comment

      • Andy Hassall

        #4
        Re: $HTTP_SERVER_VA RS['SCRIPT_FILENAM E'] - getting all GET vars too?

        On Mon, 06 Dec 2004 14:13:29 +0100, Michael Fesser <netizen@gmx.ne t> wrote:
        [color=blue]
        > .oO(Andy Hassall)
        >[color=green]
        >>On 5 Dec 2004 07:25:00 -0800, bissatch@yahoo. co.uk (mr_burns) wrote:
        >>[color=darkred]
        >>>I am using $HTTP_SERVER_VA RS['SCRIPT_FILENAM E'][/color]
        >>
        >> $_SERVER would be preferred, but it's the same info.[/color]
        >
        >Same info, but not the same scope. $_SERVER is superglobal, the old
        >$HTTP_* arrays are not.[/color]

        True.
        [color=blue][color=green]
        >>but looping through $_GET may be useful if:
        >>
        >>(a) you want to modify/add/remove some of the values, but keep the rest
        >>(b) you want to change the separator, e.g. from & to ;[/color]
        >
        >This can also be done with modifying 'arg_separator. input' if possible.[/color]

        Well, having that set might be _why_ you'd want to rewrite URLs to use ';'
        instead of '&' (which browsers tend to send), rather than _how_. I tend to have
        arg_separator.i nput set to '&;', and write out URLs separated with ';' mostly
        because it's easier than escaping & into &amp; all over the place.
        arg_separator.o utput handles anything where PHP constructs URLs, but I think
        that's mostly just the form rewriting it does for cookie-less sessions.

        --
        Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
        <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

        Comment

        Working...