Setting variables from GET request

This is a discussion on Setting variables from GET request within the PHP Language forums, part of the PHP Programming Forums category; PHP Newb here... How do I configure php to take a url like this mydomain.com/index.php?v1=value1&...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-16-2005
Sean Berry
 
Posts: n/a
Default Setting variables from GET request

PHP Newb here...

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

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

Thanks.


Reply With Quote
  #2 (permalink)  
Old 02-16-2005
Jan Pieter Kunst
 
Posts: n/a
Default Re: Setting variables from GET request

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



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.
Reply With Quote
  #3 (permalink)  
Old 02-16-2005
Derek Fountain
 
Posts: n/a
Default Re: Setting variables from GET request

> 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'].


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.derekfountain.org/">Derek Fountain</a>
Reply With Quote
  #4 (permalink)  
Old 02-16-2005
Sean Berry
 
Posts: n/a
Default 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=(somevalue)...

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.


Reply With Quote
  #5 (permalink)  
Old 02-16-2005
Geoff Berrow
 
Posts: n/a
Default Re: Setting variables from GET request

I noticed that Message-ID: <oLKQd.32731$6u.17692@fed1read02> from Sean
Berry contained the following:

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


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/
Reply With Quote
  #6 (permalink)  
Old 02-16-2005
Dave Patton
 
Posts: n/a
Default Re: Setting variables from GET request

"Sean Berry" <sean@buildingonline.com> wrote in
news:oLKQd.32731$6u.17692@fed1read02:

> I should have probably included a better explanation in
> the original post...


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/
Reply With Quote
  #7 (permalink)  
Old 02-16-2005
Sean Berry
 
Posts: n/a
Default Re: Setting variables from GET request


"Dave Patton" <spam@trap.invalid> wrote in message
news:Xns95FF69DD64BEBmrzaphoddirectcaold@24.71.223 .159...
> "Sean Berry" <sean@buildingonline.com> wrote in
> news:oLKQd.32731$6u.17692@fed1read02:
>
>> I should have probably included a better explanation in
>> the original post...

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


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.



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:22 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0