Connecting Tech Pros Worldwide Help | Site Map

change URL variables

 
LinkBack Thread Tools Search this Thread
  #1  
Old February 28th, 2007, 12:55 PM
abscons@gmail.com
Guest
 
Posts: n/a
Default change URL variables

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.


  #2  
Old February 28th, 2007, 01:05 PM
Sjoerd
Guest
 
Posts: n/a
Default 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
  #3  
Old February 28th, 2007, 01:15 PM
abscons@gmail.com
Guest
 
Posts: n/a
Default 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.

  #4  
Old February 28th, 2007, 08:45 PM
BKDotCom
Guest
 
Posts: n/a
Default 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.

  #5  
Old February 28th, 2007, 10:35 PM
abscons@gmail.com
Guest
 
Posts: n/a
Default 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


  #6  
Old March 1st, 2007, 04:25 AM
Jerry Stuckle
Guest
 
Posts: n/a
Default 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
==================
  #7  
Old March 1st, 2007, 03:35 PM
abscons@gmail.com
Guest
 
Posts: n/a
Default 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


  #8  
Old March 1st, 2007, 07:45 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default 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
==================
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.