Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to change one parameter in the URL request ?

1 view
Skip to first unread message

Christophe Cerbourg

unread,
May 27, 2003, 6:09:20 AM5/27/03
to
Hello,

I'm not far from a complete newbie with PHP and I wonder how to change only
the value of one variable in the URL request, when I don't know the others ?

example :
http://MyWebSite.com/MyPage.php?var1=12&var22=xxx&var147=444&var87=aaaa

I only would like to add 1 to var147, without changing anything else in the
string, and I don't know how to do this in PHP.

Thanks for any help !
Christophe


Tyrone Slothrop

unread,
May 27, 2003, 11:15:52 AM5/27/03
to

The simplest solution that comes to mind is something like:
$url = "http://www.mysite.com/page.php?var1=" . $_GET[var1] .
"&var22=" . $_GET[var22] . "&var147=" . ($_GET[var147] + 1) .
"&var87=" . $_GET[var87;
header ("location:$url");

All this does is extract the $_GET values and performs the numerical
calculation, Of course you will likely want to add some error
trapping and redirection to a default page if there is an error.

Jim Hughes

unread,
May 27, 2003, 11:51:46 AM5/27/03
to
"Christophe Cerbourg" <c.cer...@ouanadoo.fr> wrote in message
news:bavdg6$d4j$1...@news-reader14.wanadoo.fr...

From the PHP Manual:

Example 135. Traversing $_POST with each()
copy to clipboard
echo "Values submitted via POST method:<br />\n";
reset ($_POST);
while (list ($key, $val) = each ($_POST)) {
echo "$key => $val<br />\n";
}

So you could use something like (untested)

$url = basename($PHP_SELF) . "?";
reset($_GET);
while (list ($key, $val) = each ($_GET)) {
if ($key == var147) {
$url .= "$key=" . ($val + 1) . "&";
} else {
$url .= "$key=$val&";
}
}

Andrew Ho

unread,
May 27, 2003, 12:49:42 PM5/27/03
to
"Christophe Cerbourg" <c.cer...@ouanadoo.fr> wrote in message news:<bavdg6$d4j$1...@news-reader14.wanadoo.fr>...

um....I'm not sure what you mean. surely just requesting:
http://MyWebSite.com/MyPage.php?var1=12&var22=xxx&var147=445&var87=aaaa
would do the trick? where are you trying to add this from? if you
mean when you pass the variable onto MyPage.php, you want to add one,
then:
$var147 = $_REQUEST['var147'] + 1;
should work?
if you explain a bit more, maybe we can help

hth.
andrew

Christophe Cerbourg

unread,
May 27, 2003, 1:41:48 PM5/27/03
to
thanks tyrone for your help but problem is I only know the name of the
variable that I'm interested with, not the other ones that I want to keep as
it...

Christophe Cerbourg

unread,
May 27, 2003, 1:42:59 PM5/27/03
to
thanks a lot Jim, I think I will manage to get somthing with what you showed
me (if I all understand it, but it seems to...) !


Christophe Cerbourg

unread,
May 27, 2003, 1:44:45 PM5/27/03
to
thanks Andrew for your help...
problem is that I only know the name of 1 variable, and I only want to
increment it, never touch anything else in the request string...

Anyway, it seems Jim's solution will fit, thanks for your help !


Kevin Thorpe

unread,
May 28, 2003, 6:25:01 AM5/28/03
to

If you are trying to preserve parameters between requests like this then
it points towards the use of session variables. Each page can then
manipulate only the session vars it knows about, the others will be
automatically presewrved for you.

andreas halter

unread,
May 28, 2003, 7:01:29 AM5/28/03
to
hi Christophe,

Christophe Cerbourg was scribbeling:


>
http://MyWebSite.com/MyPage.php?var1=12&var22=xxx&var147=444&var87=aaaa
>
> I only would like to add 1 to var147, without changing anything else
> in the string, and I don't know how to do this in PHP.

you might also want to have a look at QUERY_STRING:

http://www.php.net/manual/en/reserved.variables.php#reserved.variables.server
hth andreas
--
collect xul annotations: http://xul.andreashalter.ch/

0 new messages