473,795 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 21903
ab*****@gmail.c om 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.c om 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(a rray('var'=>'ne w_value'));
// may seem like a lot of code, but I use these 2 funcs all the time.

function get_self_link($ new_get_vars=ar ray(),$full_url =false)
{
$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($cur rent_url);
$query = get_query_strin g($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_strin g($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.c om 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.c om 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.c om 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*******@attgl obal.net
=============== ===
Mar 1 '07 #6
On Mar 1, 12:09 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
absc...@gmail.c om wrote:
On Feb 28, 8:57 am, Sjoerd <sjoerd-n...@linuxonly. nlwrote:
absc...@gmail.c om 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...@attgl obal.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.c om wrote:
On Mar 1, 12:09 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>absc...@gmail. com wrote:
>>On Feb 28, 8:57 am, Sjoerd <sjoerd-n...@linuxonly. nlwrote:
absc...@gmai l.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...@attg lobal.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*******@attgl obal.net
=============== ===
Mar 1 '07 #8

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

Similar topics

2
1762
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 Root is unadvisable, thus im working on breaking up my long scripts into files to be included from the main page through the <? required() ?> tag. So herein lies the question. how can i safely set/alter the same variables from across several...
3
1952
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 display:block but then whenever I have to make a change to the block I have to update in two places? Any help would be appreciated. My example: <xsl:if test="RequirementGroup/@ReqMet = &quot;Y&quot;">
1
3610
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" type=radio value="James">James <input name="student" type=checkbox value="yes">student? and now: if student=yes then this boy is a student:
0
1368
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 dynamic, so I need to be able to change variables for parameters on the fly. I'm pretty much a flash dummy, but here's what my component parameters look like. http://i15.tinypic.com/664vzbo.jpg And the code I'm using to embed it into my website...
10
2123
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 site to change as the query does so a link in my site would change to www.thescripts.com/qwerty
20
4045
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 tells me if a variable has changed, give me the original and current value, and whether the current value and original value is/was null or not. This one works fine but is recreating the same methods over and over for each variable type. ...
1
29385
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 called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this condition. The opinions expressed in this article are those of the author alone although many have...
33
1812
by: sophia.agnes | last post by:
Dear all, consider the following program #include<stdio.h> #include<unistd.h> main() { int pid,*i,j;
5
1341
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 how can i do that?
7
2435
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 assign the values everytime someone loaded the page so it would always come up different. Does that make sense? Is that something that Javascript can do? I know basically how to generate the random number. I just don't know how to get that to be...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.