[PHP] $_GET String Edit

2003-11-22 Thread Jed R. Brubaker
Hey  - this one should be simple.

I am parsing some data and have $_GET variables in the URL stipulating on
which record to start and how many records to display (these then get basses
to the limit command in my database query).

So here is the catch. I am trying to make a page navigation menu (we have
all seen them, Page: 1 2 3...), and I would like to continue doing this
via the URL variables.  Right now, each of the page numbers is a hyper link
is set like this:

page.php?.$_SERVER[QUERY_STRING].more variables here.

The problem, however, is that those variables are a string. If the variables
that the menu defines are already in the string, it doesn't update them, it
just adds more definitions to the URL.

How have you people dealt with this? I am sure that there is some elegant
solution and I would love to know what it is.

Thanks in advance!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] $_GET String Edit

2003-11-22 Thread Chris Shiflett
--- Jed R. Brubaker [EMAIL PROTECTED] wrote:
 I am trying to make a page navigation menu (we have all seen them,
 Page: 1 2 3...), and I would like to continue doing this via the
 URL variables. Right now, each of the page numbers is a hyper link
 is set like this:
 
 page.php?.$_SERVER[QUERY_STRING].more variables here.
 
 The problem, however, is that those variables are a string. If the
 variables that the menu defines are already in the string, it
 doesn't update them, it just adds more definitions to the URL.

I had a hard time interpreting your question, but I think you're saying
that you are generating URLs like this:

/page.php?foo1=bar1foo2=bar2foo1=bar3foo2=bar4

And, you're wanting to not duplicate variables in your URL, correct?

You could always keep your query string in an array or something. This
would allow you to update values in the array prior to the end of your
script. You can start this array using $_GET:

$query = $_GET;

Of course, you might want to rather filter this data on each page, so that
you don't spread tainted data more than necessary. Regardless, this will
allow you to update values in your query string. If you want to update
foo1, you don't have to care whether it's already set:

$query['foo1'] = 'newvalue';

Hope that helps.

Chris

=
Chris Shiflett - http://shiflett.org/

PHP Security Handbook
 Coming mid-2004
HTTP Developer's Handbook
 http://httphandbook.org/
RAMP Training Courses
 http://www.nyphp.org/ramp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] $_GET String Edit

2003-11-22 Thread Jed R. Brubaker
Sorry for the confusing initial request.
You were correct in assuming that I am generating URLs like:
page.php?foo1=bar1foo2=bar2foo1=bar3foo2=bar4

So I suppose the consise follow-up question is how can I get a hyperlink to
change one of those varibles in the string.

In the past I have just tacked a varible on to the end of the string, but I
don't want to be redundant.

Thanks again.


Chris Shiflett [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 --- Jed R. Brubaker [EMAIL PROTECTED] wrote:
  I am trying to make a page navigation menu (we have all seen them,
  Page: 1 2 3...), and I would like to continue doing this via the
  URL variables. Right now, each of the page numbers is a hyper link
  is set like this:
 
  page.php?.$_SERVER[QUERY_STRING].more variables here.
 
  The problem, however, is that those variables are a string. If the
  variables that the menu defines are already in the string, it
  doesn't update them, it just adds more definitions to the URL.

 I had a hard time interpreting your question, but I think you're saying
 that you are generating URLs like this:

 /page.php?foo1=bar1foo2=bar2foo1=bar3foo2=bar4

 And, you're wanting to not duplicate variables in your URL, correct?

 You could always keep your query string in an array or something. This
 would allow you to update values in the array prior to the end of your
 script. You can start this array using $_GET:

 $query = $_GET;

 Of course, you might want to rather filter this data on each page, so that
 you don't spread tainted data more than necessary. Regardless, this will
 allow you to update values in your query string. If you want to update
 foo1, you don't have to care whether it's already set:

 $query['foo1'] = 'newvalue';

 Hope that helps.

 Chris

 =
 Chris Shiflett - http://shiflett.org/

 PHP Security Handbook
  Coming mid-2004
 HTTP Developer's Handbook
  http://httphandbook.org/
 RAMP Training Courses
  http://www.nyphp.org/ramp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] $_GET String Edit

2003-11-22 Thread Chris Shiflett
--- Jed R. Brubaker [EMAIL PROTECTED] wrote:
 Sorry for the confusing initial request. You were correct in assuming
 that I am generating URLs like:

 page.php?foo1=bar1foo2=bar2foo1=bar3foo2=bar4
 
 So I suppose the consise follow-up question is how can I get a
 hyperlink to change one of those varibles in the string.
 
 In the past I have just tacked a varible on to the end of the string,
 but I don't want to be redundant.

To make this easy, I really think you need to not use a string like you
keep suggesting and use some other data structure. I mentioned an array,
simply because I think one of PHP's strengths is its rich collection of
array functions.

You can build your query string as the very last step, prior to using it
in a link. While you are constructing it, I think you will find using a
string to be about the most cumbersome approach possible.

Hope that helps.

Chris

=
Chris Shiflett - http://shiflett.org/

PHP Security Handbook
 Coming mid-2004
HTTP Developer's Handbook
 http://httphandbook.org/
RAMP Training Courses
 http://www.nyphp.org/ramp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php