Forum Moderators: coopster

Message Too Old, No Replies

PHP generated 404 error pages and Googlebot

         

morags

10:54 am on Mar 30, 2006 (gmt 0)

10+ Year Member



I have a "site search" program written in PHP. All works fine - except I am unsure of what to do for "empty" searches (specifically, what header code to return).

Until now, when someone submits the form without entering any data, I have been returning a 200 OK header, and redirecting the user to the site homepage, so that the user can try again. I now read that this could cause problems, especially with Googlebot, and that I should be returning a 404 Not Found instead.

So here is my confusion:

User doesn't enter anything - I have to return something. But what? I do want to return the page he was on, so that he can try again, possibly adding a "try again" message. But what header code should I be returning?

Thanks.

barns101

1:17 pm on Mar 30, 2006 (gmt 0)

10+ Year Member



Perhaps my search facilities are operating differently to yours, because I return a list of results (links to the relevant pages) and don't bother with setting headers, just the content of the results page. If no query was submitted or no results found the page simply informs the user of that.

Hope that makes sense and I didn't miss your point. :)

jatar_k

3:41 pm on Mar 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



barns101 is correct but I will add a few things

empty searches should shoe "please enter a search term" and then redisplay the search for. There is no need to redirect as it should send a 200 and allow them to search again on that page.

at the top of your search results page (or somewhere on the page) you should always have the form there as well.

Another option is to return a default set of pages if nothing is entered. You have your message at the top of them saying there was nothing entered and then have a list of pages/products that you want to push below that.

morags

7:48 pm on Mar 30, 2006 (gmt 0)

10+ Year Member



Thanks both. No, you didn't miss the point - I was just being a bit thick.

Sylver

4:28 pm on Apr 4, 2006 (gmt 0)

10+ Year Member



For this kind of form validation, (checking if the field is empty), you should use javascript.

Much faster for the user, less traffic for your server because the page is not sent until something is actually typed in the box.

jatar_k

6:20 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if people use js for validation you still need to use php as well. users may not have js on and bots certainly don't.

only js for any form is a security no no

Sylver

3:15 am on Apr 5, 2006 (gmt 0)

10+ Year Member



Completely agree.

Both javascript and PHP validation.

Javascript is for the user because, well the vast majority of them have javascript on and it's always a nuisance to click on a form, wait a bit and then the page shows up again because you forgot something. Javascript is instant.

On the downside, it's easy for a hacker to copy your page, remove the js validation, and use the form without it, so the form needs to be validated in php as well.