ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Google custom search has stopped working after update to CodeIgniter 2 [SOLVED]

May 10, 2011 11:03pm

Subscribe [3]
  • #1 / May 10, 2011 11:03pm

    maxbel

    7 posts

    Hi all,

    I have used Google custom search on my site in the past without a hitch. I’ve recently updated to CI 2 and the search has stopped working properly.

    The search results are supposed to be displayed on the following page:
    http://www.tvcw.org/index.php/main/search

    However, every time I launch a search, I land on the main page (http://www.tvcw.org/index.php/main).

    I know the results are generated and sent by Google because if I insert Google’s search results code on the main page, the results are displayed just fine. I just can’t get the search results to appear on the right page (the “search” page).

    Here is the URL generated by the Google custom search (“test” being the search word):
    http://tvcw.org/index.php/main/search/?cx=009193659681247254929:gvqvfabvrgw&cof=FORID:10&ie=UTF-8&q=test&sa=Rechercher&siteurl=www.tvcw.org/index.php

    Here is the code for the search box:

    <form action="http://tvcw.org/index.php/main/search/" id="cse-search-box">
      <div>
        <input type="hidden" name="cx" value="009193659681247254929:gvqvfabvrgw" />
        <input type="hidden" name="cof" value="FORID:10" />
        <input type="hidden" name="ie" value="UTF-8" />
        <input type="text" name="q" size="31" />
        <input type="submit" name="sa" value="Rechercher" />
      </div>
    </form>
    [removed][removed]

    Here is the search results code: (inserted in the search page at http://www.tvcw.org/index.php/main/search)

    <div id="cse-search-results"></div>
    [removed]
      var googleSearchIframeName = "cse-search-results";
      var googleSearchFormName = "cse-search-box";
      var googleSearchFrameWidth = 600;
      var googleSearchDomain = "www.google.com";
      var googleSearchPath = "/cse";
    [removed]
    [removed][removed]

    Thanks for the help!

  • #2 / May 11, 2011 3:13am

    John_Betong_002

    407 posts

    I have Google search working OK on http://johns-jokes.com/

    The way I do it is to:
    1. save the two Google scripts to files _Google_search.php and _Google_search_results.php
    2. include the scripts where required.

    The Google search results are displayed in a div on my main page.
     
     

  • #3 / May 11, 2011 10:40am

    maxbel

    7 posts

    The way I do it is to:
    1. save the two Google scripts to files _Google_search.php and _Google_search_results.php
    2. include the scripts where required.

    The Google search results are displayed in a div on my main page.
     
     


    That’s exactly how I also do it. If I put the results code on the mainpage of my site, everything works fine.

    The only difference is that my search results used to be displayed on a seperate results page (before update). Now, even though the form action still points to the “search” function in my “main” controller…

    <form action="http://tvcw.org/index.php/main/search/" id="cse-search-box">

    ... it never gets there. he only thing that has changed is the update to CI 2.

    For some reason, even if the generated URL contains “http://tvcw.org/main/search”+Google generated code, everything stops at “main” and never gets to “search” in the controller.

    Am I making sense? I can provide more code if needed.

    You can check it out and try the search (lower right) at http://tvcw.org/main.

    It should send you to the search page, http://tvcw.org/main/search, and display the results.


    Thanks!

  • #4 / May 11, 2011 12:06pm

    John_Betong_002

    407 posts

    I tried searching and here are the results:

    Google Search Page:
    http://tvcw.org/index.php/main/search/?cx=009193659681247254929:gvqvfabvrgw&cof=FORID:10&ie=UTF-8&q=sex+feed+your+world&sa=Rechercher&siteurl=tvcw.org/main/search/

    404 Page Not Found
    The page you requested was not found.

    I think the problem is with incorrect routing. Try this:

    ./application/config/routes.php

    $route["main/search/(:any)"] = "main/search/$1";

    I assume you have a main.php controller with function search().

    Controller main.php

    function search()
    {
      // debug code
      echo __METHOD__;
      die;
    }

     

  • #5 / May 11, 2011 1:56pm

    John_Betong_002

    407 posts

    Just modified my site, added routing to a page without blank main content, minus top advert, thumbnails, comments, blurb, etc.

    Now works fine so it looks as though my guess to your problem was correct.

    I have no idea if the CI2 code has changed but it looks as though additional safety filtering has been added.
     
     

  • #6 / May 12, 2011 5:39pm

    maxbel

    7 posts

    Thanks for your help John,the ROUTES idea was a good one. Sadly,the proposed solution does not fix the problem.

    I have noticed something odd that might be part of the problem or something else altogether:

    When I enter only one word into the search bar, the search works but I get dumped on my MAIN page because the controller never gets by INDEX() to the SEARCH() function.

    When there is a space in the search query, as in when your search has at least 2 words, I get the 404 error you got.

    The only thing different is a plus sign “+” in the URI when I use more than one search word.
    Adding the plus sign to

    $config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';

    doesn’t change anything. =,&,and ? aren’t specified as permitted URI characters yet they get by fine. I don’t understand…

    I also noticed the end of the URI generated form a search on your site has a # followed by 4 digits. I don’t get that on my side. Do you know what they are for?
    Ex.: http://johns-jokes.com/Google-search-results?cx=partner-pub-0332427512321583:tdwk46fltrn&cof=FORID:10&ie=UTF-8&q=funny+dog&sa=Search&siteurl=johns-jokes.com/#1146

    I’m going to keep fiddling with the routes to see if I can make something work.

  • #7 / May 12, 2011 10:24pm

    maxbel

    7 posts

    Does anybody else have problems using Google custom search with CI 2?

    Is anyone using an other easy to implement solution for searching through their site?

  • #8 / May 13, 2011 1:46am

    John_Betong_002

    407 posts

    Hi Maxbel,

    Two things:

    Firstly, I noticed that replacing a comma with space between search words does not create “Page not found”.

    Secondly, your config permitted setting is incorrect, you are missing a backslash.

    Take a look at the CI2 config.php installation file:

    $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

     

  • #9 / May 13, 2011 3:36pm

    CroNiX

    4713 posts

    Do you have security tokens enabled?

  • #10 / May 14, 2011 9:38am

    iversonchen

    5 posts

    be honest, i do not know much about this questions. trying to understand.

  • #11 / May 19, 2011 11:14am

    maxbel

    7 posts

    Do you have security tokens enabled?

    No, they are not enabled.

  • #12 / May 19, 2011 11:18am

    maxbel

    7 posts

    Hi Maxbel,

    Two things:

    Firstly, I noticed that replacing a comma with space between search words does not create “Page not found”.

    Secondly, your config permitted setting is incorrect, you are missing a backslash.

    Take a look at the CI2 config.php installation file:

    $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

     


    You’re right John, there was a mistake in the permitted URI line. It doesn’t fix the problem though.

    I also noticed that the search query worked with the coma. Now, if I can get all my users to use comas in their queries…  😊

    Still trying to get to the results page though…

  • #13 / May 26, 2011 12:29am

    John_Betong_002

    407 posts

    Today my Google Search stopped working :(

    For quite some time I have had a problem with third party sites with incorrect links to my Jokes site and Google Webmaster Tools was complaining. Today I fixed that problem and the Google Search stopped working.

    // incorrect link now handled gracefully
    http://johns-jokes.com/afiles/images/saw_009_overloaded.jpg width=“66” height=“50” alt=“image”></a> </div> <div class=“c0 r”><a

  • #14 / May 26, 2011 10:45am

    maxbel

    7 posts

    Hey John,

    Have you already fixed the problem? I just tried the search on your site and it seemed to work fine.

    What was, or is, the actual problem? Maybe we can help…

  • #15 / May 26, 2011 11:47am

    John_Betong_002

    407 posts

    Hey John,

    Have you already fixed the problem? I just tried the search on your site and it seemed to work fine.

    What was, or is, the actual problem? Maybe we can help…

    This Forum was being updated around the time I posted the following code and it looks as though there was a problem during the update.

    During testing to get the error_404.php to work I changed the .htaccess file and Google Search stopped working.

    Check to see it the line is in your .htaccess file. 

    RewriteCond %{HTTP_HOST} !^johns-jokes.com$ [NC]
      RewriteCond $1!^(index\.php|images|css|robots\.txt|favicon\.ico|Sitemap\.xml)
        
      # Removing next line causes Google-Search-Results to fail
      RewriteRule ^(.*)$ <a href="http://johns-jokes.com/$1">http://johns-jokes.com/$1</a> [L,R=301]
    
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
    
      RewriteRule ^(.*)$ index.php/$1 [L,QSA]

     
     
     

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases