473,396 Members | 2,109 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,396 software developers and data experts.

ampersand problem when passing multiple parameters in URL

Hi,

when I try to pass some parameters in an URL, I always get an URL where the
ampersand is represented as '&'.

I tried:

$url = "wsp.php?mod=$mod&sec=$sym";
$url = "wsp.php?mod=$mod" . '&' . "sec=$sym";

and many other variations.

The result is always the same (for $mod=adm and $sec=usr):

'wsp.php?mod=adm&sec=usr'

The ampersand seems to be masked by some unwanted functionality.
So, how can I get my URL as follows:

'wsp.php?mod=adm&sec=usr'

Thank you very much,
Magnus
Jul 16 '05 #1
5 34683
Magnus Warker wrote:
Hi,

when I try to pass some parameters in an URL, I always get an URL where
the ampersand is represented as '&'.

I tried:

$url = "wsp.php?mod=$mod&sec=$sym";
$url = "wsp.php?mod=$mod" . '&' . "sec=$sym";

and many other variations.

The result is always the same (for $mod=adm and $sec=usr):

'wsp.php?mod=adm&sec=usr'

The ampersand seems to be masked by some unwanted functionality.
So, how can I get my URL as follows:

'wsp.php?mod=adm&sec=usr'

Thank you very much,
Magnus

It's meant to be & if it's in an html page.

--
Matt Mitchell - AskMeNoQuestions
Dynamic Website Development and Marketing
Jul 16 '05 #2

On 4-Aug-2003, Magnus Warker <ma****@gmx.de> wrote:
when I try to pass some parameters in an URL, I always get an URL where
the
ampersand is represented as '&amp;'.

I tried:

$url = "wsp.php?mod=$mod&sec=$sym";
$url = "wsp.php?mod=$mod" . '&' . "sec=$sym";

and many other variations.

The result is always the same (for $mod=adm and $sec=usr):

'wsp.php?mod=adm&amp;sec=usr'

The ampersand seems to be masked by some unwanted functionality.
So, how can I get my URL as follows:

'wsp.php?mod=adm&sec=usr'


The only way & would get changed to &amp; is if you run the string through
htmlspecialchars() or a similar function. Post the code.

--
Tom Thackrey
www.creative-light.com
Jul 16 '05 #3
Hi Tom,

here is the code. The function should print a table item with a label ($lbl)
which is a link to a workspace ($wsp) containing two parameters, a module
($mod) and a section ($sym):

function mod_idx_itm ($mod,$sym,$lbl)
{
$url = "wsp.php?mod=$mod&sec=$sym";
print " <td align='left' nowrap>\n";
echo " <a href='" . "$url" . "'>$lbl</a>\n";
print " </td>\n";
}

Matty:
You mean, &amp; in URLs is really correct and works??

Magnus
Tom Thackrey wrote:
The only way & would get changed to &amp; is if you run the string through
htmlspecialchars() or a similar function. Post the code.


Jul 16 '05 #4
Magnus Warker <ma****@gmx.de> writes:
You mean, &amp; in URLs is really correct and works??


It's *correct* if it's output to HTML for the browser to parse - so
<a href="example.php?this=2&amp;that=1">
or
<img src="exampleimage.php?this=2&amp;that=1" alt=" ">

Works in every browser I've tested in (ranging from Mozilla 1.4 down
to Netscape 1) - not entity referencing the & to &amp; is known to
break at times.

It's *not correct* if it's being used for internal purposes in PHP
header("Location: http://www.example.com/example.php?this=1&that=2");
or
include("http://www.example.com/example.php?this=1&that=2");

--
Chris
Jul 16 '05 #5
Magnus Warker wrote:

Matty:
You mean, &amp; in URLs is really correct and works??

Magnus


If it's in an HTML page, yes! The urls are actually *meant* to be like this,
and if they're not, they're actually invalid. If you're storing it in a database,
or sending an HTTP header, then no, it shouldn't be entity escaped.

$url='http://myserver.com/?this=that&me=you';

print '<a href="'.htmlentities($url).'">'; ...

but
header('Location: '.$url."\r\n");

HTH
Jul 16 '05 #6

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

Similar topics

3
by: VM | last post by:
Can collections help me pass several parameters to a method? For example, I need to pass 10 different string and integer values to one method. How would I declare a Collections type, store these 10...
7
by: Anne | last post by:
hie there, i want to be able to pass multiple parameters to another page. currently, i am able to do so, but somehow i feel it is not the correct way to do it. below is part of what i have so far....
3
by: cdg | last post by:
Is there any reason why code passing multiple parameters with a vector is not legal. I have left out most of the unneccessary details to try and make the problem clearer. Earlier in the program...
3
by: ZMan | last post by:
The following code won't compile with gcc version 3.4.2 (mingw-special). How come? Error: cannot convert `char (*)' to `char**' /**********************************************************/...
4
by: Nathan Sokalski | last post by:
I am a beginner with AJAX, and have managed to learn how to use it when passing single parameters, but I want to return more than one value to the client-side JavaScript function that displays it....
5
by: Code Monkey | last post by:
Is there anyway I can start a get a job done by starting a new thread with MULTIPLE parameters? operations only take a maximum of 1 parameter? I need a way of passing (at minimum) at least 3...
4
by: abhishekbrave | last post by:
Hi Can we pass a value through hyperlink. My requirement is that suppose i have 3 hyperlinks 1 2 3 When I click on 1 or 2 or 3 another HTML page will get open having the information that "1 is...
8
by: Yansky | last post by:
If I have the following function: function foo(){ alert('hi'); } and I don't need to pass any parameters to it, is calling it this way:
3
by: raylopez99 | last post by:
I suspect the answer to this question is that it's impossible, but how do I make the below code work, at the point where it breaks (marked below). See error CS0411 This is the complete code. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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,...
0
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...
0
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
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,...

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.