We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48586
    • 78 Posts
    Last week I had an issue where the number 1 was showing up in place of an image, now I am having an issue where the 1 is randomly showing up instead of a snippet I have running across the top of my site. Has this ever happened to anyone else before? This has now happened to me 3 times, on 3 separate areas of the site, and I'm not sure where to even start looking.

    Thank you.
      • 3749
      • 24,544 Posts
      What version of MODX?

      If you set the debug System Setting to -1 temporarily, you should get a PHP error message when the problem occurs that might tell you where it's coming from.

      Also, take a look in the MODX Error Log to see if there's anything helpful there.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 48586
        • 78 Posts
        I am using MODX Revolution 2.3.1-pl

        Unfortunately I'm not sure if error log will help, we have a dev server behind a firewall, it takes about 15-20 minutes to push to a couple load balancing production servers, and we do not push the manager folder to the live web. I am unable to duplicate the issue on our dev environment, it is only happening on the live servers.

        I will try to set debug to -1 later this evening to see what happens, my only concern doing it now is that it is a very high volume site and the debug message would display to end users for ~20 minutes until pushes are complete.

        Hopefully, that will shed some light to this situation, and help anyone in the future who runs into this issue
          • 48586
          • 78 Posts
          Follow up on this issue, but not really sure what the fix can be here. My site is location based for 6 primary markets, so when you come to the site, it looks up IP and is supposed to populate the site with correct market values.

          I have a header nav on the site above logo that is a snippet that has a 3rd party chat code so the chat link only shows up when an agent is available, and also only displays a specific link for 3 of the markets. The number "1" shows up in place of the snippet whenever I manually clear the cache folder on our production servers, and then seems to fix itself after 12-24 hours.

          This is a very strange issue, and a band-aid fix is limiting manual cache clear until late evenings, but if anyone has ever experienced anything like this before and has a better fix please let me know.

          Thank you very much.

          Edit: The reason we built in a manual cache clear script is because when we make updates to custom database tables it doesn't always update on the site [ed. note: rjohnson375 last edited this post 8 years, 7 months ago.]
            • 37377
            • 64 Posts
            Can you post the code of your snippets and chunks?
              • 48586
              • 78 Posts
              Quote from: culd at Sep 07, 2015, 01:21 PM
              Can you post the code of your snippets and chunks?

              I'm digging through the trail of chunks and snippets to post, this is my fist MODX site and it was a learning process. So, in my templates, I am calling a generic top part of the code in a chunk, and in that chunk I am calling uncached my topNavigation snippet:

              topNavigation snippet
              <?php
              // Set URL for anchor page navigation
                if ($_SERVER['SERVER_NAME'] == 'dev.mysite.net') {
                  $fwdAnchorLink = "http://dev.mysite.net";
                } else {
                  $fwdAnchorLink = "http://www.mysite.com";
                }
                
              switch ($_COOKIE['market']) {
                  case "city1":
                      $fields = array('market_link' => 'city1',
                      'fwdAnchorLink' => $fwdAnchorLink);
                      $output .= $modx->getChunk('top_nav', $fields);
                      break;
                  case "city2":
                      $fields = array('market_link' => 'city2',
                      'fwdAnchorLink' => $fwdAnchorLink,
                      'someCityShow' => '<li><a href="http://www.mysite.com/extralink/" target="_blank">Extra Link</a></li>'););
                      $output .= $modx->getChunk('top_nav', $fields);
                      break;
                  etc....
              }
              
              return $output;


              top_nav chunk
              <div class="top-nav-container">
                  <div class="inner">
                      <nav class="top-nav">
                          <ul>
                              [[!showChatLink? &ids=`18,19,22,23,24,25,26,27,28,29,30,31` &extendedChunk=`chatLinkChunk` &basicChunk=`noChatLinkChunk`]]
                              <li class="contact">800-123-4567</li>
                              <li><a href="link" target="_blank">Link 1</a></li>
                              <li><a href="link" target="_blank">Link 2</a></li>
                              <li><a href="link" target="_blank">Link 3</a></li>
                              [[+someCityShow]]
                          </ul>
                      </nav>
                      <div class="off-link" align="center">
                          <a href="http://www.mysite-business.com/" style="padding: 10px 22px; height: 52px; line-height: 1em !important; font-size: 1rem;" target="_blank">For Business<br /><span style="font-weight: normal; font-size: .8em; text-align: center;">800-321-7654</span></a>
                      </div>
                  </div>
              </div>


              I think I may have used fwdAnchorLink in another snippet, and it is just a ghost here, but it is necessary to have someplace in my code in order for anchor links to work on my pages.

              The show chat link snippet is just to display the script for chat on certain pages, and is pretty basic:

              showChatLink
              <?php
              $ids = explode(',',$modx->getOption('ids',$scriptProperties,''));
              $docid = $modx->resource->get('id');
                
              if (in_array($docid,$ids)) {
                $chunk = $extendedChunk;
              } else {
                $chunk = $basicChunk;
              }
              return $modx->getChunk($chunk);


              So, I can't find anything in the code that would cause a "1" to show up instead of my code, it's pretty basic. The only thing I can maybe think of is that it is being called uncached, but, if it isn't then my extra link for some cities won't show up until the next load of the page. I know it isn't the chat code because I am even running into issues on pages that it isn't being used. It might also be my geo location initial landing and for some reason clearing server cache is causing a cookie mix-up and showing the "1", but I don't understand why.

              Just to show, here is my geo location snippet which is Resource 1, so there is no official landing page, just a redirect to the different markets:

              geoIP
              <?php
              include("/path-to-site/assets/geo/geoipcity.inc");
              include("/path-to-site/assets/geo/geoipregionvars.php");
              
              $ip_address = $_SERVER['REMOTE_ADDR'];
              $gi = geoip_open("/path-to-site/assets/geo/GeoLiteCity.dat", GEOIP_STANDARD);
              
              $record = geoip_record_by_addr($gi, $ip_address); 
              $request_uri = $_SERVER['REQUEST_URI'];
              
              $cookie_market = $_COOKIE['market'];
              
              
              if (isset($_COOKIE['market'])) {
              
                  switch ($_COOKIE['market']) {
              
                    case 'city1':
                      echo $modx->sendRedirect('city1/',array('type' => 'REDIRECT_HEADER'));
                      break;
              
                    case 'city2':
                      echo $modx->sendRedirect('city2/',array('type' => 'REDIRECT_HEADER'));
                      break;
              
                    case 'city3':
                      echo $modx->sendRedirect('city3/',array('type' => 'REDIRECT_HEADER'));
                      break;
              
                    default:
                      echo $modx->sendRedirect('city1/',array('type' => 'REDIRECT_HEADER'));
                      break;
                    
                  }
                  
              
              } else {
                  
                  if ( ($record->country_code == 'US') and ($cookie_market == '') ) {
              
                  switch ($record->region) {
              
                    case 'TX':
                      $ip_market = 'city1';
                      header("Set-Cookie: market=$ip_market; Path=/; Expires=".gmdate('D, d M Y H:i:s \G\M\T',time()+720*60*60));
                      echo $modx->sendRedirect('city1/',array('type' => 'REDIRECT_HEADER'));
                      break;
              
                    case 'FL':
                      $ip_market = 'city2';
                      header("Set-Cookie: market=$ip_market; Path=/; Expires=".gmdate('D, d M Y H:i:s \G\M\T',time()+720*60*60));
                      echo $modx->sendRedirect('city2/',array('type' => 'REDIRECT_HEADER'));
                      break;
              
                    case 'CA':
                      $ip_market = 'city3';
                      header("Set-Cookie: market=$ip_market; Path=/; Expires=".gmdate('D, d M Y H:i:s \G\M\T',time()+720*60*60));
                      echo $modx->sendRedirect('city3/',array('type' => 'REDIRECT_HEADER'));
                      break;
                      
                    default:
                      $ip_market = 'city1';
                      header("Set-Cookie: market=$ip_market; Path=/; Expires=".gmdate('D, d M Y H:i:s \G\M\T',time()+720*60*60));
                      echo $modx->sendRedirect('city1/',array('type' => 'REDIRECT_HEADER'));
                      break;
                    
                  }
                  
              }
              
              geoip_close($gi);
              
              }

                • 37377
                • 64 Posts
                At first sight I don't see any mistakes. I think the best you can do is exclude snippets and chunks to narrow down what's causing it.
                  • 3749
                  • 24,544 Posts
                  First of all, you don't want to echo $modx->sendRedirect(). It forwards the user immediately and produces no useful output (except maybe a 1).

                  Second, the first argument to it should probably be a full URL, complete with http//.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 48586
                    • 78 Posts
                    Quote from: BobRay at Sep 10, 2015, 08:57 PM
                    First of all, you don't want to echo $modx->sendRedirect(). It forwards the user immediately and produces no useful output (except maybe a 1).

                    Second, the first argument to it should probably be a full URL, complete with http//.

                    Thanks Bob, so in the case of my geoIP snippet to redirect based on market should it be something like:

                    geoIP
                    if (isset($_COOKIE['market'])) {
                     
                        switch ($_COOKIE['market']) {
                     
                          case 'city1':
                            $url = $modx->makeUrl(18);
                            $modx->sendRedirect($url);
                            break;
                     
                          case 'city2':
                            $url = $modx->makeUrl(22);
                            $modx->sendRedirect($url);
                            break;
                     
                          case 'city3':
                            $url = $modx->makeUrl(24);
                            $modx->sendRedirect($url);
                            break;
                     
                          default:
                            $url = $modx->makeUrl(18);
                            $modx->sendRedirect($url);
                            break;
                           
                        }
                         
                     
                    } else {
                    ...


                    It is most important that the city stay in the URL, so http://www.mysite.com/city1/ and http://www.mysite.com/city2/ are the landing pages of the site (there is no http://www.mysite.com/). This is for analytic reporting, webmaster tools, and local keyword marketing.

                    Or, should I use these as my cases instead?

                    $modx->sendForward(18);
                    $modx->sendForward(22);
                    etc...


                    I'm just really confused, because it only happens when I clear cache on production servers, and it isn't a constant issue I can replicate. It happens on some page refreshes, fixes itself on other page refreshes, and isn't a consistent issue on navigation of the site. The geoIP is only used when someone comes to http://www.mysite.com/, if I go directly to http://www.mysite.com/city1/services-landing/service-2/ sometimes I get the "1", sometimes I don't.

                    Maybe the issue is one of the cached folders on prod server needs to stay cached, and I have to write a rule to exclude deleting that folder, and only go in once every couple months and manually delete it.

                    Thank you very much, I really appreciate your help.
                      • 3749
                      • 24,544 Posts
                      I would control the url by setting the alias of each document. Use this form for the redirect:

                      $modx->sendRedirect($url, "", "", "full");

                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting