Zen Cart Logo
Forums / General Questions / ampersands in URLs

ampersands in URLs

Locked

Views: 5,017

Results 1 to 20 of 28
This thread is locked. New replies are disabled.
26 Sep 2007, 5:26 PM
#1
rstevenson avatar

rstevenson

Totally Zenned

Join Date:
Nov 2006
Location:
Dartmouth, NS Canada
Posts:
2,400
Plugin Contributions:
0

ampersands in URLs

Hi,

About the only thing that throws warnings when I validate my Zen Cart pages are the ampersands in the URLs of any links on the page. You know, where the link address is like...

http://www.mysite.com/store/index.php?main_page=index&cPath=37

That red ampersand causes an error which cascades into subsequent arrors. It should be written out as &

The w3.org site has a nice article about this and how to fix it, but I need advice on implementing it within Zen Cart. They suggest starting the php script with this...

<?php ini_set('arg_separator.output','&'); ?>

Could one of the experts tell me how to do that within Zen Cart?

TIA

Rob

26 Sep 2007, 5:31 PM
#2
merlinpa1969 avatar

merlinpa1969

Totally Zenned

Join Date:
Mar 2004
Posts:
13,031
Plugin Contributions:
4

Re: ampersands in URLs

This should already be happening in stock ZC

26 Sep 2007, 5:36 PM
#3
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: ampersands in URLs

Not really, at least for the categories' names.

26 Sep 2007, 5:55 PM
#4
crazycucumber avatar

crazycucumber

Zen Follower

Join Date:
Jan 2006
Posts:
403
Plugin Contributions:
0

Re: ampersands in URLs

Just installed latest zen cart to do a new site , and ampersands still appear in the URL , Therefore you can never pass the w3c HTML check,

If someone has this rewrite working can they let us know how.

26 Sep 2007, 7:15 PM
#5
rstevenson avatar

rstevenson

Totally Zenned

Join Date:
Nov 2006
Location:
Dartmouth, NS Canada
Posts:
2,400
Plugin Contributions:
0

Re: ampersands in URLs

Merlinpa1969:

This should already be happening in stock ZC

Well, the URL I posted above is an actual one (except for the domain name of course) so it's not working right on my sites. Drop in for a visit and see.

Are there other issues that can cause this? Maybe server settings? Other mods? Phase of the moon? Temperature of Kim's coffee?:lookaroun

Rob

26 Sep 2007, 7:49 PM
#6
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,641
Plugin Contributions:
0

Re: ampersands in URLs

Rob -

Which site(s) are giving you a problem?

26 Sep 2007, 7:58 PM
#7
rstevenson avatar

rstevenson

Totally Zenned

Join Date:
Nov 2006
Location:
Dartmouth, NS Canada
Posts:
2,400
Plugin Contributions:
0

Re: ampersands in URLs

Both of mine - links below.

For example, validating the main page of the retail site yields...

Line 131, Column 75: cannot generate system identifier for general entity "cPath".

…ore/index.php?main_page=product_info&cPath=80_84&products_id=215"><img src="i

✉

An entity reference was found in the document, but there is no reference by that name defined. Often this is caused by misspelling the reference name, unencoded ampersands, or by leaving off the trailing semicolon (;). The most common cause of this error is unencoded ampersands in URLs as described by the WDG in "Ampersands in URLs". ... etc.

Rob

26 Sep 2007, 8:51 PM
#8
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,641
Plugin Contributions:
0

Re: ampersands in URLs

Rob -

The errors do not appear to be caused by content generated by Zen Cart, but rather by links that have been added - Just replace the & with & in all URLs you have added.

Note: They may have to re-done if you edit the content after your initial customization.

26 Sep 2007, 9:44 PM
#9
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: ampersands in URLs

Kim, I have the same problem, the links are category links which are generated by zen_href_link (or something like that, I don't remember the exact function name). Also, one of my categories (used to) contains a &, and it was not encoded correctly either.

26 Sep 2007, 9:54 PM
#10
merlinpa1969 avatar

merlinpa1969

Totally Zenned

Join Date:
Mar 2004
Posts:
13,031
Plugin Contributions:
4

Re: ampersands in URLs

This is copy paste of the categories from a test site running 1.3.7
as you can see the & is actually &

<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=1">Hardware-></a> (6)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=2">Software-></a> (4)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=3">DVD Movies-></a> (17)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=21">Gift Certificates</a> (6)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=22">Big Linked</a> (24)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=23">Test Examples</a> (16)<br />

<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=28">Test 10%</a> (7)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=25">Test 10% by Attrib</a> (3)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=24">Free Call Stuff</a> (7)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=33">A Top Level Cat-></a><br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=48">Sale Percentage-></a> (7)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=49">Sale Deduction-></a> (4)<br />

<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=50">Sale New Price-></a> (4)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=53">Big Unlinked</a> (12)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=54">New v1.2-></a> (20)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=62">Music</a> (1)<br />
<a class="category-top" href="http://demodomain.com/index.php?main_page=index&cPath=64">Mixed Product Types</a> (5)<br />
26 Sep 2007, 10:04 PM
#11
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,641
Plugin Contributions:
0

Re: ampersands in URLs

Kim, I have the same problem, the links are category links which are generated by zen_href_link (or something like that, I don't remember the exact function name). Also, one of my categories (used to) contains a &, and it was not encoded correctly either.

Without a URL - I can't help ...

26 Sep 2007, 10:14 PM
#12
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: ampersands in URLs

http://k o n k i t o.com is the link (without all the spaces of course)

Thank you.

26 Sep 2007, 10:25 PM
#13
rstevenson avatar

rstevenson

Totally Zenned

Join Date:
Nov 2006
Location:
Dartmouth, NS Canada
Posts:
2,400
Plugin Contributions:
0

Re: ampersands in URLs

Kim:

Rob -

The errors do not appear to be caused by content generated by Zen Cart, but rather by links that have been added - Just replace the & with & in all URLs you have added.

Note: They may have to re-done if you edit the content after your initial customization.

Oooooh, I hate it when it's my fault! :oops:

You're right, it is something I put in using the Define Pages Editor. And just about every time I change that image on the main page, I forget those damn ampersands, since I'm just copying and pasting a URL.

Sorry!

Rob

26 Sep 2007, 10:27 PM
#14
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,641
Plugin Contributions:
0

Re: ampersands in URLs

Again - the errors are not in code generated by the stock Zen Cart - your errors are in custom URLs.

Example:

	```html
<div id="nav_tab_1"> <div id="nav_home" class="nav_main"><a href="index.php?main_page=index&sort=1d&main_nav=1">Home</a></div> <div id="nav_konkito" class="nav_main"><a href="index.php?main_page=index&sort=1d&main_nav=2">My Konkito.com</a></div> ```
26 Sep 2007, 10:29 PM
#15
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,641
Plugin Contributions:
0

Re: ampersands in URLs

Rob -

Not to worry. We do need to know if the code Zen Cart generates is validating. :)

26 Sep 2007, 10:50 PM
#16
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: ampersands in URLs

This is how the link is generated:

<a href="index.php?<?php echo my_get_all_get_params(array('main_nav'));?>main_nav=1">Home</a>

my_get_all_get_params is just zen_get_all_get_params, but I took out 1 of the conditions so that it will include the main_page parameter in the generated link (the original does not)

Do you have any suggestion for this case, Kim?

26 Sep 2007, 11:37 PM
#17
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,641
Plugin Contributions:
0

Re: ampersands in URLs

It is your function - have it use &amp: instead of & ???

26 Sep 2007, 11:38 PM
#18
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: ampersands in URLs

It's the same as zen_get_all_get_params Kim, I just take out the part that would omit main_page

function my_get_all_get_params($exclude_array = '', $search_engine_safe = true) {

    if (!is_array($exclude_array)) $exclude_array = array();

    $get_url = '';
    if (is_array($_GET) && (sizeof($_GET) > 0)) {
      reset($_GET);
      while (list($key, $value) = each($_GET)) {
        if ( (strlen($value) > 0) && ($key != zen_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {
          if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
//      die ('here');
            $get_url .= $key . '/' . rawurlencode(stripslashes($value)) . '/';
          } else {
            $get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&';
          }
        }
      }
    }
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);

    return $get_url;
  }
26 Sep 2007, 11:42 PM
#19
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: ampersands in URLs

Here is the original one, as you see I only remove: ($key != 'main_page')

// Return all HTTP GET variables, except those passed as a parameter
  function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {

    if (!is_array($exclude_array)) $exclude_array = array();

    $get_url = '';
    if (is_array($_GET) && (sizeof($_GET) > 0)) {
      reset($_GET);
      while (list($key, $value) = each($_GET)) {
        if ( (strlen($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {
          if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
//      die ('here');
            $get_url .= $key . '/' . rawurlencode(stripslashes($value)) . '/';
          } else {
            $get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&';
          }
        }
      }
    }
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
    while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);

    return $get_url;
  }
27 Sep 2007, 1:43 AM
#20
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: ampersands in URLs

Try using zen_href_link() to build your links instead of zen_get_all_get_params(). The get-all-get-params is a helper function, not a URL-builder.