Setting variables from GET request

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

    Setting variables from GET request

    PHP Newb here...

    How do I configure php to take a url like this
    mydomain.com/index.php?v1=va lue1&v2=value2& v3=value3

    and automagically create varialbe $v1 throught $v3 and assign
    the corresponding values?

    Thanks.


  • Jan Pieter Kunst

    #2
    Re: Setting variables from GET request

    Sean Berry wrote:[color=blue]
    > PHP Newb here...
    >
    > How do I configure php to take a url like this
    > mydomain.com/index.php?v1=va lue1&v2=value2& v3=value3
    >
    > and automagically create varialbe $v1 throught $v3 and assign
    > the corresponding values?[/color]


    extract($_GET) will do that. Personally I like to be able to see at a
    glance where my variables come from, so I would use $_GET['v1'] through
    $_GET['v3'].

    JP

    --
    Sorry, <devnull@cauce. org> is a spam trap.
    Real e-mail address unavailable. 5000+ spams per month.

    Comment

    • Derek Fountain

      #3
      Re: Setting variables from GET request

      > extract($_GET) will do that. Personally I like to be able to see at a[color=blue]
      > glance where my variables come from, so I would use $_GET['v1'] through
      > $_GET['v3'].[/color]

      Me too. Actually I habitually do something like:

      $v1 = sanitise( $_GET['v1'] );
      unset $_GET['v1'];

      so I use the conveniently named variable, but only after ensuring it is safe
      to do so. Taking shortcuts with user supplied values isn't a good idea,
      IMHO.

      --
      The email address used to post is a spam pit. Contact me at
      http://www.derekfountain.org : <a
      href="http://www.derekfounta in.org/">Derek Fountain</a>

      Comment

      • Sean Berry

        #4
        Re: Setting variables from GET request

        I should have probably included a better explanation in
        the original post... so here goes.

        I have several php scripts written by a third party that
        are being hosted on my servers. The scripts work
        fine on the servers that they were written on, but
        seem to have a recurring problem on my servers.

        Both servers have PHP v. 4.3.6.

        The problem that keeps coming up is that the author
        of the scripts uses a lot of
        if (isset($varname )) {
        do something;
        }

        But, $varname is never set explicitly like this:
        $varname = $_GET('varname' );

        When I add the types of assignments above, pieces start
        to work. But there are nearly 100 php files, and lots
        of vars in each.

        For example - the variable $cid is never set explicitly via
        $id = $_GET('cid');
        yet mysql querries using $cid as a variable work fine on
        his server - as long as the url contains ...&cid=(someva lue)...

        The only reason I could come up with as to why the scripts
        act differently on his server vs. mine is that he must have compiled
        php to do the variable parsing and assignment from a GET request
        automatically. Is there any other explanation?

        Thanks for any and all help.


        Comment

        • Geoff Berrow

          #5
          Re: Setting variables from GET request

          I noticed that Message-ID: <oLKQd.32731$6u .17692@fed1read 02> from Sean
          Berry contained the following:
          [color=blue]
          >The only reason I could come up with as to why the scripts
          >act differently on his server vs. mine is that he must have compiled
          >php to do the variable parsing and assignment from a GET request
          >automaticall y. Is there any other explanation?[/color]

          The reason is that he has register globals on and you don't. As your
          setup is now regarded as being the better option, you are right and he
          is wrong.

          Your script author should know this and should be prepared to fix the
          scripts. But beware of quick and dirty fixes like using extract()

          <says he, having to do exactly that this afternoon to get a script
          working again quickly. Heh...>

          --
          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

          • Dave Patton

            #6
            Re: Setting variables from GET request

            "Sean Berry" <sean@buildingo nline.com> wrote in
            news:oLKQd.3273 1$6u.17692@fed1 read02:
            [color=blue]
            > I should have probably included a better explanation in
            > the original post...[/color]

            Actually, you shouldn't have posted the same question
            more than once ;-)

            I answered your posting in alt.php

            What is the accepted way to share a message across multiple newsgroups?


            --
            Dave Patton
            Canadian Coordinator, Degree Confluence Project

            My website: http://members.shaw.ca/davepatton/

            Comment

            • Sean Berry

              #7
              Re: Setting variables from GET request


              "Dave Patton" <spam@trap.inva lid> wrote in message
              news:Xns95FF69D D64BEBmrzaphodd irectcaold@24.7 1.223.159...[color=blue]
              > "Sean Berry" <sean@buildingo nline.com> wrote in
              > news:oLKQd.3273 1$6u.17692@fed1 read02:
              >[color=green]
              >> I should have probably included a better explanation in
              >> the original post...[/color]
              >
              > Actually, you shouldn't have posted the same question
              > more than once ;-)
              >
              > I answered your posting in alt.php
              >
              > What is the accepted way to share a message across multiple newsgroups?
              > http://smjg.port5.com/faqs/usenet/xpost.html
              >
              > --
              > Dave Patton
              > Canadian Coordinator, Degree Confluence Project
              > http://www.confluence.org/
              > My website: http://members.shaw.ca/davepatton/[/color]

              Dave,

              Sorry about crossposting - this is actually my first time doing so.

              I was worried that nobody was going to read my revised post.

              Also, thank you for pointing out the link clarifying the proper way
              to post to multiple groups.



              Comment

              Working...