Connecting Tech Pros Worldwide Forums | Help | Site Map

change URL variables

abscons@gmail.com
Guest
 
Posts: n/a
#1: Feb 28 '07
Hi out there,
I have an url that looks like this: http://host/file?var=value.
I am trying to replace the "value" part in my url and assign it to a
link on my page. I tried to parse the url but can only get the part
before the ? not included.

Is there any way to do so?

Thx.


Sjoerd
Guest
 
Posts: n/a
#2: Feb 28 '07

re: change URL variables


abscons@gmail.com wrote:
Quote:
Hi out there,
I have an url that looks like this: http://host/file?var=value.
I am trying to replace the "value" part in my url and assign it to a
link on my page. I tried to parse the url but can only get the part
before the ? not included.
>
Is there any way to do so?
Yes. What do you have so far? Have you looked at $_SERVER[QUERY_STRING]
and $_SERVER[REQUEST_URI]?

http://nl3.php.net/manual/en/reserve...riables.server
abscons@gmail.com
Guest
 
Posts: n/a
#3: Feb 28 '07

re: change URL variables


On Feb 28, 8:57 am, Sjoerd <sjoerd-n...@linuxonly.nlwrote:
Quote:
absc...@gmail.com wrote:
Quote:
Hi out there,
I have an url that looks like this:http://host/file?var=value.
I am trying to replace the "value" part in my url and assign it to a
link on my page. I tried to parse the url but can only get the part
before the ? not included.
>
Quote:
Is there any way to do so?
>
Yes. What do you have so far? Have you looked at $_SERVER[QUERY_STRING]
and $_SERVER[REQUEST_URI]?
>
http://nl3.php.net/manual/en/reserve...erved.variable...
Thx.
I tried the REQUEST_URI but didn't work. I'll look at your link and
update when I go back to my project. Thx.

BKDotCom
Guest
 
Posts: n/a
#4: Feb 28 '07

re: change URL variables



// this will replace (and/or add) parameters to the query string
$new_url = get_self_link(array('var'=>'new_value'));
// may seem like a lot of code, but I use these 2 funcs all the time.

function get_self_link($new_get_vars=array(),$full_url=fals e)
{
$string = '';
$get_vars = $_GET;
foreach ( $new_get_vars as $k=>$v )
$get_vars[$k] = $v;
$protocol = ( isset($_SERVER['HTTPS']) &&
$_SERVER['HTTPS']=='on' ) ? 'https' : 'http';
$current_url = $protocol.'://'.$_SERVER['HTTP_HOST'].
$_SERVER['REQUEST_URI'];
$url_parts = @parse_url($current_url);
$query = get_query_string($get_vars);
if ( $full_url )
$string = $protocol.'://'.$_SERVER['HTTP_HOST'];
$string .= $url_parts['path'].$query;
return $string;
}

/************************************************** **********/
// similar to http://www.php.net/function.http-build-query
// does not handle arrays
function get_query_string($attribs)
{
$query = '?';
foreach ( $attribs as $k=>$v )
{
if ( $v !== null && !is_array($v) )
{
$query .= $k;
$query .= '='.str_replace('%2F','/',urlencode($v));
$query .= '&';
}
}
$query = substr($query,0,-1);
$query = str_replace('&','&amp;',$query);
return $query;
}

On Feb 28, 7:40 am, absc...@gmail.com wrote:
Quote:
Hi out there,
I have an url that looks like this:http://host/file?var=value.
I am trying to replace the "value" part in my url and assign it to a
link on my page. I tried to parse the url but can only get the part
before the ? not included.
>
Is there any way to do so?
>
Thx.

abscons@gmail.com
Guest
 
Posts: n/a
#5: Feb 28 '07

re: change URL variables


On Feb 28, 8:57 am, Sjoerd <sjoerd-n...@linuxonly.nlwrote:
Quote:
absc...@gmail.com wrote:
Quote:
Hi out there,
I have an url that looks like this:http://host/file?var=value.
I am trying to replace the "value" part in my url and assign it to a
link on my page. I tried to parse the url but can only get the part
before the ? not included.
>
Quote:
Is there any way to do so?
>
Yes. What do you have so far? Have you looked at $_SERVER[QUERY_STRING]
and $_SERVER[REQUEST_URI]?
>
http://nl3.php.net/manual/en/reserve...erved.variable...
This is the error I get when using REQUEST_URI: Notice: Undefined
index: REQUEST_URI


Jerry Stuckle
Guest
 
Posts: n/a
#6: Mar 1 '07

re: change URL variables


abscons@gmail.com wrote:
Quote:
On Feb 28, 8:57 am, Sjoerd <sjoerd-n...@linuxonly.nlwrote:
Quote:
>absc...@gmail.com wrote:
Quote:
>>Hi out there,
>>I have an url that looks like this:http://host/file?var=value.
>>I am trying to replace the "value" part in my url and assign it to a
>>link on my page. I tried to parse the url but can only get the part
>>before the ? not included.
>>Is there any way to do so?
>Yes. What do you have so far? Have you looked at $_SERVER[QUERY_STRING]
>and $_SERVER[REQUEST_URI]?
>>
>http://nl3.php.net/manual/en/reserve...erved.variable...
>
This is the error I get when using REQUEST_URI: Notice: Undefined
index: REQUEST_URI
>
>
It needs to be:

$_SERVER['REQUEST_URI']

Note the quotes - this is an index in the $_SERVER array.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
abscons@gmail.com
Guest
 
Posts: n/a
#7: Mar 1 '07

re: change URL variables


On Mar 1, 12:09 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
absc...@gmail.com wrote:
Quote:
On Feb 28, 8:57 am, Sjoerd <sjoerd-n...@linuxonly.nlwrote:
Quote:
absc...@gmail.com wrote:
>Hi out there,
>I have an url that looks like this:http://host/file?var=value.
>I am trying to replace the "value" part in my url and assign it to a
>link on my page. I tried to parse the url but can only get the part
>before the ? not included.
>Is there any way to do so?
Yes. What do you have so far? Have you looked at $_SERVER[QUERY_STRING]
and $_SERVER[REQUEST_URI]?
>>
Quote:
This is the error I get when using REQUEST_URI: Notice: Undefined
index: REQUEST_URI
>
It needs to be:
>
$_SERVER['REQUEST_URI']
>
Note the quotes - this is an index in the $_SERVER array.
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
My exact call are:
$url = $_SERVER['REQUEST_URI'];
echo "URI: ".$url."<br/>";

and still: Notice: Undefined index: REQUEST_URI in index.php on line
21


Jerry Stuckle
Guest
 
Posts: n/a
#8: Mar 1 '07

re: change URL variables


abscons@gmail.com wrote:
Quote:
On Mar 1, 12:09 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
>absc...@gmail.com wrote:
Quote:
>>On Feb 28, 8:57 am, Sjoerd <sjoerd-n...@linuxonly.nlwrote:
>>>absc...@gmail.com wrote:
>>>>Hi out there,
>>>>I have an url that looks like this:http://host/file?var=value.
>>>>I am trying to replace the "value" part in my url and assign it to a
>>>>link on my page. I tried to parse the url but can only get the part
>>>>before the ? not included.
>>>>Is there any way to do so?
>>>Yes. What do you have so far? Have you looked at $_SERVER[QUERY_STRING]
>>>and $_SERVER[REQUEST_URI]?
>>>http://nl3.php.net/manual/en/reserve...erved.variable...
>>This is the error I get when using REQUEST_URI: Notice: Undefined
>>index: REQUEST_URI
>It needs to be:
>>
> $_SERVER['REQUEST_URI']
>>
>Note the quotes - this is an index in the $_SERVER array.
>>
>--
>==================
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>jstuck...@attglobal.net
>==================
>
My exact call are:
$url = $_SERVER['REQUEST_URI'];
echo "URI: ".$url."<br/>";
>
and still: Notice: Undefined index: REQUEST_URI in index.php on line
21
>
>
Well, it should work, if your server is passing it on to PHP. Which
server are you using?

What does phpinfo() show? It should show REQUEST_URI.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Closed Thread