Re: Appending to the REQUEST_URI

From: Date: Wed, 28 May 2003 20:41:57 +0000
Subject: Re: Appending to the REQUEST_URI
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-149315@lists.php.net to get a copy of this message
You have to check for it, regardless. See if this works for you. $url = $_SERVER['REQUEST_URI'] . '?' . ((isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] . '&' : '' ) . 'newVar=1'; The middle part basically sees if the QUERY_STRING is empty. If it is, it includes a question mark otherwise it includes an apersand. Actually, to be fully compliant, replace the & with &amp; in your URLs. $url = $_SERVER['REQUEST_URI'] . '?' . ((isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] . '&amp;' : '' ) . 'newVar=1'; It'll work, trust me. :) ---John Holmes... ----- Original Message ----- From: "Matt Grimm" <mgrimm@healthtvchannel.org> To: <php-general@lists.php.net> Sent: Wednesday, May 28, 2003 4:12 PM Subject: [PHP] Appending to the REQUEST_URI Let's say I have a table with links in the headers for sorting each column. I want to carry the sort variable along in the $_GET array, and I need to be able to pass other variables to this same page, also using the GET method. My trouble is when I need to append a new variable to the REQUEST_URI -- I need to detect whether a QUERY_STRING has already been passed, so I won't use "?" when I need "&" in the URI. Here's my clunky attempt: <a href="<?php echo $_SERVER['REQUEST_URI']; if ($_SERVER['QUERY_STRING'] && !$_GET['newVar']) { echo "&newVar=1"; } else if (!$_SERVER['QUERY_STRING']) { echo "?newVar=1"; } ?> ">link description text</a> Please tell me there is some way to just append to the query string without checking it first... -- Matt Grimm Web Developer The Health TV Channel, Inc. (a non - profit organization) 3820 Lake Otis Parkway Anchorage, AK 99508 907.770.6200 ext. 686 907.336.6205 (fax) E-mail: mgrimm@healthtvchannel.org Web: www.healthtvchannel.org

« previous php.general (#149315) next »