ampersand problem when passing multiple parameters in URL

Ask a Question related to PHP Development, Design and Development.

  1. #1

    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
    Magnus Warker Guest

  2. Similar Questions and Discussions

    1. Passing Parameters To CFC
      I am testing how to return data from a CFC within Flash Forms. I have a simple <cfselect> tag that will hold data returned from a CFC. This CFC...
    2. CFContent Problem - Passing parameters in URL with imgsrc tag
      Hi All, My code is like this on the ViewImage.cfm page <img src="GetImage.cfm?id=123"> on the GetImage.cfm page <cfcontent type="image/gif"...
    3. passing parameters
      Hi Michael, I think you want to modify the links in web control programmatically. You can add several Hyperlink controls to the user control,...
    4. Problem passing parameters usign DynaLib
      Hi, I want to call functions that I have in dynamic library (written in C) from a perl program. I'll try it using the module DynaLib but I´m...
    5. Help Passing Parameters
      Before going to the third script I'd suggest storing the variables in session variables. Here's how I generally do login scripts. Perhaps have...
  3. #2

    Default Re: ampersand problem when passing multiple parameters in URL


    On 4-Aug-2003, Magnus Warker <magnus@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
    [url]www.creative-light.com[/url]
    Tom Thackrey Guest

  4. #3

    Default Re: ampersand problem when passing multiple parameters in URL

    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 '&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'
    >
    > Thank you very much,
    > Magnus
    It's meant to be &amp; if it's in an html page.

    --
    Matt Mitchell - AskMeNoQuestions
    Dynamic Website Development and Marketing
    matty Guest

  5. #4

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

  6. #5

    Default Re: ampersand problem when passing multiple parameters in URL

    Magnus Warker <magnus@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
    Chris Morris Guest

  7. #6

    Default Re: ampersand problem when passing multiple parameters in URL

    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
    matty Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139