CodeIgniter Forums

Full Version: Google custom search has stopped working after update to CodeIgniter 2 [SOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]maxbel[/eluser]
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/?c.../index.php

Here is the code for the search box:

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

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

Code:
<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!

El Forum

[eluser]John_Betong_002[/eluser]
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.
&nbsp;
&nbsp;

El Forum

[eluser]maxbel[/eluser]
[quote author="John_Betong_002" date="1305112384"]
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.
&nbsp;
&nbsp;[/quote]


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...
Code:
&lt;form action="http://tvcw.org/index.php/main/search/" id="cse-search-box"&gt;
... 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!

El Forum

[eluser]John_Betong_002[/eluser]
I tried searching and here are the results:

Google Search Page:
http://tvcw.org/index.php/main/search/?c...in/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
Code:
$route["main/search/(:any)"] = "main/search/$1";

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

Controller main.php
Code:
function search()
{
  // debug code
  echo __METHOD__;
  die;
}

&nbsp;

El Forum

[eluser]John_Betong_002[/eluser]
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.
&nbsp;
&nbsp;

El Forum

[eluser]maxbel[/eluser]
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
Code:
$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-res...jokes.com/#1146

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

El Forum

[eluser]maxbel[/eluser]
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?

El Forum

[eluser]John_Betong_002[/eluser]
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:

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

El Forum

[eluser]CroNiX[/eluser]
Do you have security tokens enabled?

El Forum

[eluser]iversonchen[/eluser]
be honest, i do not know much about this questions. trying to understand.
Pages: 1 2