Setting variables from GET request

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

PHP Newb here...

How do I configure php to take a url like this

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


Re: Setting variables from GET request

Sean Berry wrote:
Quoted text here. Click to load it

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


Real e-mail address unavailable. 5000+ spams per month.

Re: Setting variables from GET request

Quoted text here. Click to load it

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,

The email address used to post is a spam pit. Contact me at : <a
href=" /">Derek Fountain</a>

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.

Re: Setting variables from GET request

Berry contained the following:

Quoted text here. Click to load it

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 /

Re: Setting variables from GET request

Quoted text here. Click to load it

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

Re: Setting variables from GET request

Quoted text here. Click to load it


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.

Site Timeline