There are IP->Country databases from companies like GeoMind (I think), but it does not come cheaply (not that they are of poor quality -- it's just not a cheap service). Other than that, there may be a way to ascertain a person's LANGUAGE setting, but that's about it.
My advice to you would be to ask the user what settings he or she wants on their first visit. For example, if you ultimately want to redirect based on langauge, have the user select a language, and set a cookie. Next time they load your page, have the initial script check for the cookie, and redirect accordingly.
Also, keep in mind that just because someone is FROM Spain does not mean that he or she wants to read in Spanish. That's another benefit of the ask-once-then-cookie method.
And, there is more good news: cookies are a breeze in PHP.