FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Names of URL Parameters
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Names of URL Parameters [message #175424] Wed, 21 September 2011 20:56 Go to next message
eBob.com is currently offline  eBob.com
Messages: 11
Registered: August 2011
Karma: 0
Junior Member
I know that I can get and print the value of a URL parameter this way ...

echo '<p>phone: ' . $_GET['phone'] . '</p>';

.... and that works fine of course. But what if I don't know the names of
all the parameters and just want to print out the names and values of all
the parameters? (It might not seem to make a lot of sense, but it would be
useful to me in experimenting/developing/debugging.)

It looks like (I haven't tried it) $_SERVER['QUERY_STRING'] would give me
the entire URL but I'd really rather not have to parse it.

Thanks, Bob (a very new noob)
Re: Names of URL Parameters [message #175425 is a reply to message #175424] Wed, 21 September 2011 21:06 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
eBob.com wrote:
> I know that I can get and print the value of a URL parameter this way ...
>
> echo '<p>phone: ' . $_GET['phone'] . '</p>';
>
> ... and that works fine of course. But what if I don't know the names
> of all the parameters and just want to print out the names and values of
> all the parameters? (It might not seem to make a lot of sense, but it
> would be useful to me in experimenting/developing/debugging.)
>
> It looks like (I haven't tried it) $_SERVER['QUERY_STRING'] would give
> me the entire URL but I'd really rather not have to parse it.
>
> Thanks, Bob (a very new noob)

$_GET[] is an array

Look at the manual on how to print a whole array.
Re: Names of URL Parameters [message #175426 is a reply to message #175424] Wed, 21 September 2011 21:46 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
eBob.com wrote:
^^^^^^^^
You really want to put a real name there. I usually don't talk to domains.

> I know that I can get and print the value of a URL parameter this way ...
>
> echo '<p>phone: ' . $_GET['phone'] . '</p>';
>
> ... and that works fine of course. But what if I don't know the names of
> all the parameters and just want to print out the names and values of all
> the parameters? (It might not seem to make a lot of sense, but it would
> be useful to me in experimenting/developing/debugging.)
>
> It looks like (I haven't tried it) $_SERVER['QUERY_STRING'] would give me
> the entire URL but I'd really rather not have to parse it.

Think about it: Why does $_GET['phone'] work in the first place?

> Thanks, Bob (a very new noob)
^^^^^^^^^^^^^
Don't.

<http://catb.org/~esr/faqs/smart-questions.html#id478703>


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
Re: Names of URL Parameters [message #175427 is a reply to message #175426] Thu, 22 September 2011 03:27 Go to previous messageGo to next message
eBob.com is currently offline  eBob.com
Messages: 11
Registered: August 2011
Karma: 0
Junior Member
Yes, of course. Thank you PointedEars and Natural Philosopher. Although I
have done a lot of programming in many different languages, I am brand new
to PHP, and this was my first experience of any kind with arrays. It just
wasn't clicking that 'phone' (in my example) was a subscript. I don't think
I've used a language before in which plain ol' arrays can have character
string "subscripts".

Thanks again for the help.

Bob


"Thomas 'PointedEars' Lahn" <PointedEars(at)web(dot)de> wrote in message
news:1888520(dot)Oct5B3EuLq(at)PointedEars(dot)de...
> eBob.com wrote:
> ^^^^^^^^
> You really want to put a real name there. I usually don't talk to
> domains.
>
>> I know that I can get and print the value of a URL parameter this way ...
>>
>> echo '<p>phone: ' . $_GET['phone'] . '</p>';
>>
>> ... and that works fine of course. But what if I don't know the names of
>> all the parameters and just want to print out the names and values of all
>> the parameters? (It might not seem to make a lot of sense, but it would
>> be useful to me in experimenting/developing/debugging.)
>>
>> It looks like (I haven't tried it) $_SERVER['QUERY_STRING'] would give me
>> the entire URL but I'd really rather not have to parse it.
>
> Think about it: Why does $_GET['phone'] work in the first place?
>
>> Thanks, Bob (a very new noob)
> ^^^^^^^^^^^^^
> Don't.
>
> <http://catb.org/~esr/faqs/smart-questions.html#id478703>
>
>
> PointedEars
> --
> Use any version of Microsoft Frontpage to create your site.
> (This won't prevent people from viewing your source, but no one
> will want to steal it.)
> -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
Re: Names of URL Parameters [message #175428 is a reply to message #175427] Thu, 22 September 2011 12:43 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
On Wed, 21 Sep 2011 23:27:18 -0400, eBob.com wrote:

> Yes, of course. Thank you PointedEars and Natural Philosopher.
> Although I have done a lot of programming in many different languages,
> I am brand new to PHP, and this was my first experience of any kind
> with arrays. It just wasn't clicking that 'phone' (in my example) was
> a subscript. I don't think I've used a language before in which plain
> ol' arrays can have character string "subscripts".

Other languages probably just called them "hashes" instead. The
difference is largely semantics, in either direction.

--
Every fleeting thought you've ever had in your life, no matter how
bizarre, is someone's lifelong obsession. And he has a website.
-- Skif's Internet Theorem
Re: Names of URL Parameters [message #175429 is a reply to message #175427] Thu, 22 September 2011 17:36 Go to previous messageGo to next message
Richard Damon is currently offline  Richard Damon
Messages: 58
Registered: August 2011
Karma: 0
Member
On 9/21/11 11:27 PM, eBob.com wrote:
> Yes, of course. Thank you PointedEars and Natural Philosopher. Although
> I have done a lot of programming in many different languages, I am brand
> new to PHP, and this was my first experience of any kind with arrays. It
> just wasn't clicking that 'phone' (in my example) was a subscript. I
> don't think I've used a language before in which plain ol' arrays can
> have character string "subscripts".
>
> Thanks again for the help.
>
> Bob
>
>

Actually, those aren't "plain ol' arrays" but associative arrays, which
just happen to use the same syntax as the simple linear array.
Re: Names of URL Parameters [message #175455 is a reply to message #175424] Wed, 28 September 2011 18:46 Go to previous messageGo to next message
tamouse is currently offline  tamouse
Messages: 5
Registered: September 2011
Karma: 0
Junior Member
Since the question seems directed to debugging, you should know about two functions: print_r and var_dump:

http://us2.php.net/manual/en/function.print-r.php
http://us2.php.net/manual/en/function.var-dump.php

In both of these cases, the standard behaviour is to dump the variable structure straight to the standard output (most likely your browser window/tab). This can be problematic for a few reasons, and can be a security risk if you're not careful.

print_r has a second paramter, which if set to TRUE, will return it's output as a string, which you can sanitize before sending to output thus:

echo "<pre>" . htmlentities(print_r($var,TRUE)) . "</pre>" . PHP_EOL;

This sort of thing will prove invaluable in debugging php code for the newbie.

If you're doing a fair bit of this, you might want to set up a function for debugging, and use a global to turn on/off debugging. Lots of these exist already, some very sophisticated, some very simple.

Extremely simple:

function dbg($var)
{
if ($GLOBALS['DEBUG'])
{
echo "<pre>".print_r($var,TRUE)."</pre>".PHP_EOL;
}
}

And you can set $GLOBALS['DEBUG'] in a number of ways, such as in a common configuration file that is included in your application, or by introducing a DEBUG parameter in the $_REQUEST hash.

Some people (*cough*) go so far as to write a debugger class with all sorts of fancy bells and whistles, such as including the file, function, and line number where the debugging call is made, among others.
Re: Names of URL Parameters [message #175456 is a reply to message #175455] Wed, 28 September 2011 19:18 Go to previous messageGo to next message
tamouse is currently offline  tamouse
Messages: 5
Registered: September 2011
Karma: 0
Junior Member
On Wednesday, September 28, 2011 1:46:39 PM UTC-5, tamouse wrote:

> function dbg($var)
> {
> if ($GLOBALS['DEBUG'])
> {
> echo "<pre> ".print_r($var,TRUE)."</pre>".PHP_EOL;
> }
> }

Woops. that echo line should read:

echo "<pre> ".htmlentities(print_r($var,TRUE))."</pre>".PHP_EOL;
Re: Names of URL Parameters [message #175462 is a reply to message #175455] Thu, 29 September 2011 13:15 Go to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 9/28/2011 2:46 PM, tamouse wrote:
> Since the question seems directed to debugging, you should know about two functions: print_r and var_dump:
>
> http://us2.php.net/manual/en/function.print-r.php
> http://us2.php.net/manual/en/function.var-dump.php
>
> In both of these cases, the standard behaviour is to dump the variable structure straight to the standard output (most likely your browser window/tab). This can be problematic for a few reasons, and can be a security risk if you're not careful.
>
> print_r has a second paramter, which if set to TRUE, will return it's output as a string, which you can sanitize before sending to output thus:
>
> echo "<pre>" . htmlentities(print_r($var,TRUE)) ."</pre>" . PHP_EOL;
>
> This sort of thing will prove invaluable in debugging php code for the newbie.
>
> If you're doing a fair bit of this, you might want to set up a function for debugging, and use a global to turn on/off debugging. Lots of these exist already, some very sophisticated, some very simple.
>
> Extremely simple:
>
> function dbg($var)
> {
> if ($GLOBALS['DEBUG'])
> {
> echo "<pre>".print_r($var,TRUE)."</pre>".PHP_EOL;
> }
> }
>
> And you can set $GLOBALS['DEBUG'] in a number of ways, such as in a common configuration file that is included in your application, or by introducing a DEBUG parameter in the $_REQUEST hash.
>
> Some people (*cough*) go so far as to write a debugger class with all sorts of fancy bells and whistles, such as including the file, function, and line number where the debugging call is made, among others.

I would use $_SESSION['DEBUG'] instead.

--
Shelly
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: best editor
Next Topic: discussing LeBron 8 PS
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 02:35:34 GMT 2024

Total time taken to generate the page: 0.02961 seconds