473,434 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

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.

Feb 28 '07 #1
7 21872
ab*****@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...riables.server
Feb 28 '07 #2
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...
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.

Feb 28 '07 #3

// 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:
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.

Feb 28 '07 #4
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
Feb 28 '07 #5
ab*****@gmail.com wrote:
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.
js*******@attglobal.net
==================
Mar 1 '07 #6
On Mar 1, 12:09 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
absc...@gmail.com wrote:
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
Mar 1 '07 #7
ab*****@gmail.com wrote:
On Mar 1, 12:09 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>absc...@gmail.com wrote:
>>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.
js*******@attglobal.net
==================
Mar 1 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JV | last post by:
Subject: Change variables from function Currently im working on writing login/verification scripts and I understand that leaving files that may contain sensitive information in the Document...
3
by: Jason Lehman | last post by:
I want to depending on a parameter in the XML change wether the div should display or not. Do I have to repeat the whole block in two if containers with the style display:none and one with...
1
by: norman29 | last post by:
Hi all! How can i do this: <form method="get" action="test.asp" > <input name="boys" type=radio value="John">John <input name="boys" type=radio value="Lu">Lu <input name="boys"...
0
chunkny
by: chunkny | last post by:
I'm having a little trouble getting a FLV player component to work dynamically. When the information is hardcoded from Flash MX 2004, everything works fine, but the problem is that my website is...
10
by: mcphearson2345 | last post by:
how do i get the query from an url to change variables in my website for example my website is called www.example.com so the query would be www.example.com?qwerty and i want a link in my...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
33
by: sophia.agnes | last post by:
Dear all, consider the following program #include<stdio.h> #include<unistd.h> main() { int pid,*i,j;
5
by: smartic | last post by:
I'm having PHP file that have some variables i want to read all these variables from another PHP file to change them from another page i will create,like configuration file for my site into PHP file...
7
by: dickwhyte | last post by:
What I am trying to do is this: I have a program which makes Javascript SinusPaths. To make the SinusPath there are three values. What I wanted to know how to do was use a random number generator to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.