Connecting Tech Pros Worldwide Help | Site Map

ampersand problem when passing multiple parameters in URL

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 16th, 2005, 11:00 PM
Magnus Warker
Guest
 
Posts: n/a
Default 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

  #2  
Old July 16th, 2005, 11:00 PM
matty
Guest
 
Posts: n/a
Default Re: ampersand problem when passing multiple parameters in URL

Magnus Warker wrote:
[color=blue]
> 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[/color]
It's meant to be & if it's in an html page.

--
Matt Mitchell - AskMeNoQuestions
Dynamic Website Development and Marketing
  #3  
Old July 16th, 2005, 11:00 PM
Tom Thackrey
Guest
 
Posts: n/a
Default Re: ampersand problem when passing multiple parameters in URL


On 4-Aug-2003, Magnus Warker <magnus@gmx.de> wrote:
[color=blue]
> 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'[/color]

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
  #4  
Old July 16th, 2005, 11:00 PM
Magnus Warker
Guest
 
Posts: n/a
Default Re: ampersand problem when passing multiple parameters in URL

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:
[color=blue]
> The only way & would get changed to &amp; is if you run the string through
> htmlspecialchars() or a similar function. Post the code.
>[/color]

  #5  
Old July 16th, 2005, 11:00 PM
Chris Morris
Guest
 
Posts: n/a
Default Re: ampersand problem when passing multiple parameters in URL

Magnus Warker <magnus@gmx.de> writes:[color=blue]
> You mean, &amp; in URLs is really correct and works??[/color]

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
  #6  
Old July 16th, 2005, 11:00 PM
matty
Guest
 
Posts: n/a
Default Re: ampersand problem when passing multiple parameters in URL

Magnus Warker wrote:
[color=blue]
>
> Matty:
> You mean, &amp; in URLs is really correct and works??
>
> Magnus
>
>[/color]

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
 

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,662 network members.