Hi,
I'm currently using the below geo script which works mostly fine for my purposes:
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="JavaScript">document.write(geoip_city()) ;</script>, <script language="JavaScript">document.write(geoip_region( ));</script>
It shows up as the user's city, state like this: Los Angeles, CA
But what if I wanted it to spell out the entire state name as California instead of CA, would this be possible?
use php, it is much better than javascript, you can lookup the geoip functions which return various result on the maxmind site, then just massage and extract the one you need.
And another question:
If I wanted the city name to show up capitalized like LOS ANGELES instead of Los Angeles, is this possible to do with this script?
Thanks in advance for any help!
use php, php can do wonder
okay, i understand that php may be better but i don't really know php well... and this script has been working fine for what i've been wanting except for the couple things i mentioned.
is it possible to make minor tweaks to this script to get it to do the above, or must i look to the php version to do this?
thank you tical! i was hoping there was a simple tweak to get it to show it like that!
and would you know is there a way to show it capitalized?
Probably easiest to just use CSS to control the font properties. You could use javascript but I wouldn't know how - http://www.w3schools.com/cssref/pr_t...-transform.asp
Also, be aware you're using a script hosted on someone elses server. If it can't be contact for whatever reason none of your geoip stuff will work. It's worth the effort to get GeoIP stuff installed on your own server and learn how to use PHP to deal with it. Secondly, if you run volume, i.e. many requests per hour to the geoip.js script, maxmind will block you I believe. I started with that script and I saw it go down on my second day of traffic.
Edit: I'm probably thinking of geoplugin.net w.r.t. being kicked off the script, but MaxMind might do it too.
as long as you use vps or dedi, you own the php/geoip configuration
Maxmind stops showing location after a lot of volume with js call.
Install the binaries on your own box.
Here's how to!
great! i was hoping there was a relatively easy fix for the issues i mentioned! thanks all!
n i'll also look to install on my own server as suggested. thanks everyone!
this may be a bit too technical, but i'll post in case someone knows anyhow...
so i did try to follow the instructions in pain2k's link on how to install the geo scripts on my own server but got stuck on Step 4. up til then, everything was fine. got into ssh fine, got to root and all that other good stuff.
problem is with line 5 in step 4 (./configure). after that line is entered, a bunch of stuff comes up that looks standard and fine, but then it also says this which it stops after:
“configure: error: Zlib header (zlib.h) not found. Tor requires zlib to build. You may need to install a zlib development package.”
i did try to just continue with the next line in line 6 to see if it would be okay but some other error msg comes up, which makes me think i gotta take care of this error msg first. granted, i have no idea about Tor or what it wants about installing a zlib development package. the link above doesn't mention anything about this nor do the comments from other users so i don't know what to do. i suspect tech support on my server won't be of much help as i've asked them things before and mostly i've gotten replies more or less saying, sorry, this is an unmanaged server, customer is responsible for blah blah blah.
any advice here?
Try installing zlib from the console - i.e. same place you're doing ./configure.
sudo apt-get install zlib-dev
i tried this several times but i'm getting the below msg right after i try to enter the line you suggested:
sudo: apt-get: command not found
am i doing something wrong?
Urrr try replacing "apt-get" with "yum". Refer here - http://unix.stackexchange.com/questi...mand-not-found
Package probably has a different name for your OS. Try zlib-devel or zlib1g-dev. If you could find out your server's OS then you could look it up specifically.
thanks zeno.. zlib-devel seemed to work.. and i got past step 4.. but now there's another problem, i'm sorry to say..
in step 5, it says this:
"That last command you did ‘make install’ will output the path to the new extension.
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20090626/
You need to copy that path and use it in step 7. So using your mouse, highlight that path. (In PuTTY, any text you highlight is copied to the clipboard.) Now open up Notepad and paste it so we can use it later."
i didn't see where it showed this as a bunch of stuff scrolled down the screen and when i tried to scroll up in Putty, it would only let me go up so far and i couldn't see where it showed my specific output path that it says i need to copy and paste for step 7.
so i then i tried to repeat Step 5, hoping it would show me the same info again but for some reason now, when i enter line 4 of step 5 (phpize) it now says:
-bash: phpize: command not found
i'm now starting to doubt myself in all sorts of ways, but i could've sworn it took that command the first time i entered it. is it possible it would only take that command once and the second time, it would give that error?
and at this point, how do i go about finding that specific path that it says i'll need later for step 7?
thanks zeno for all your help with this so far, i feel like an ass needing all this help with something that's supposedly so simple with step by step instructions..
cd /usr/local/lib/php/extensions/no-debug-non-zts-20090626/
ls
paste the output here
i tried again and somehow it seemed to take the 'make install' command in line 7 and it spit out a bunch of stuff after, which is below (i did change the ip address that showed because that just seems like the safe thing to do).
i still don't see anything that looks like the example given, which was:
------------------------
"That last command you did ‘make install’ will output the path to the new extension.
<<example given below this line>>
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20090626/
You need to copy that path and use it in step 7. So using your mouse, highlight that path. (In PuTTY, any text you highlight is copied to the clipboard.) Now open up Notepad and paste it so we can use it later."
------------------------
Here's what showed for me:
[root@ip-12-34-567-890GeoIP-1.4.8]# make install
Making install in libGeoIP
make[1]: Entering directory `/geotemp/GeoIP-1.4.8/libGeoIP'
make[2]: Entering directory `/geotemp/GeoIP-1.4.8/libGeoIP'
test -z "/usr/local/lib" || /bin/mkdir -p "/usr/local/lib"
/bin/sh ../libtool --mode=install /usr/bin/install -c libGeoIP.la libGeoIPUpdate.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libGeoIP.so.1.4.8 /usr/local/lib/libGeoIP.so.1.4.8
libtool: install: (cd /usr/local/lib && { ln -s -f libGeoIP.so.1.4.8 libGeoIP.so.1 || { rm -f libGeoIP.so.1 && ln -s libGeoIP.so.1.4.8 libGeoIP.so.1; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libGeoIP.so.1.4.8 libGeoIP.so || { rm -f libGeoIP.so && ln -s libGeoIP.so.1.4.8 libGeoIP.so; }; })
libtool: install: /usr/bin/install -c .libs/libGeoIP.lai /usr/local/lib/libGeoIP.la
libtool: install: warning: relinking `libGeoIPUpdate.la'
libtool: install: (cd /geotemp/GeoIP-1.4.8/libGeoIP; /bin/sh /geotemp/GeoIP-1.4.8/libtool --tag CC --mode=relink gcc -g -O2 -o libGeoIPUpdate.la -rpath /usr/local/lib GeoIPUpdate.lo md5.lo -lz libGeoIP.la )
libtool: relink: gcc -shared .libs/GeoIPUpdate.o .libs/md5.o -Wl,-rpath -Wl,/usr/local/lib -lz -L/usr/local/lib -lGeoIP -Wl,-soname -Wl,libGeoIPUpdate.so.0 -o .libs/libGeoIPUpdate.so.0.0.0
libtool: install: /usr/bin/install -c .libs/libGeoIPUpdate.so.0.0.0T /usr/local/lib/libGeoIPUpdate.so.0.0.0
libtool: install: (cd /usr/local/lib && { ln -s -f libGeoIPUpdate.so.0.0.0 libGeoIPUpdate.so.0 || { rm -f libGeoIPUpdate.so.0 && ln -s libGeoIPUpdate.so.0.0.0 libGeoIPUpdate.so.0; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libGeoIPUpdate.so.0.0.0 libGeoIPUpdate.so || { rm -f libGeoIPUpdate.so && ln -s libGeoIPUpdate.so.0.0.0 libGeoIPUpdate.so; }; })
libtool: install: /usr/bin/install -c .libs/libGeoIPUpdate.lai /usr/local/lib/libGeoIPUpdate.la
libtool: install: /usr/bin/install -c .libs/libGeoIP.a /usr/local/lib/libGeoIP.a
libtool: install: chmod 644 /usr/local/lib/libGeoIP.a
libtool: install: ranlib /usr/local/lib/libGeoIP.a
libtool: install: /usr/bin/install -c .libs/libGeoIPUpdate.a /usr/local/lib/libGeoIPUpdate.a
libtool: install: chmod 644 /usr/local/lib/libGeoIPUpdate.a
libtool: install: ranlib /usr/local/lib/libGeoIPUpdate.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/usr/local/include" || /bin/mkdir -p "/usr/local/include"
/usr/bin/install -c -m 644 GeoIP.h GeoIPCity.h GeoIPUpdate.h '/usr/local/include'
make[2]: Leaving directory `/geotemp/GeoIP-1.4.8/libGeoIP'
make[1]: Leaving directory `/geotemp/GeoIP-1.4.8/libGeoIP'
Making install in apps
make[1]: Entering directory `/geotemp/GeoIP-1.4.8/apps'
make[2]: Entering directory `/geotemp/GeoIP-1.4.8/apps'
test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
/bin/sh ../libtool --mode=install /usr/bin/install -c geoiplookup geoiplookup6 geoipupdate '/usr/local/bin'
libtool: install: /usr/bin/install -c .libs/geoiplookup /usr/local/bin/geoiplookup
libtool: install: /usr/bin/install -c .libs/geoiplookup6 /usr/local/bin/geoiplookup6
libtool: install: /usr/bin/install -c .libs/geoipupdate /usr/local/bin/geoipupdate
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/geotemp/GeoIP-1.4.8/apps'
make[1]: Leaving directory `/geotemp/GeoIP-1.4.8/apps'
Making install in conf
make[1]: Entering directory `/geotemp/GeoIP-1.4.8/conf'
make[2]: Entering directory `/geotemp/GeoIP-1.4.8/conf'
test -z "/usr/local/etc" || /bin/mkdir -p "/usr/local/etc"
/usr/bin/install -c -m 644 GeoIP.conf.default '/usr/local/etc'
make install-exec-hook
make[3]: Entering directory `/geotemp/GeoIP-1.4.8/conf'
install-exec-hook will not overwrite existing /usr/local/etc/GeoIP.conf
make[3]: Leaving directory `/geotemp/GeoIP-1.4.8/conf'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/geotemp/GeoIP-1.4.8/conf'
make[1]: Leaving directory `/geotemp/GeoIP-1.4.8/conf'
Making install in data
make[1]: Entering directory `/geotemp/GeoIP-1.4.8/data'
make[2]: Entering directory `/geotemp/GeoIP-1.4.8/data'
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/share/GeoIP" || /bin/mkdir -p "/usr/local/share/GeoIP"
/usr/bin/install -c -m 644 GeoIP.dat '/usr/local/share/GeoIP'
test -z "/usr/local/share/GeoIP" || /bin/mkdir -p "/usr/local/share/GeoIP"
make install-data-hook
make[3]: Entering directory `/geotemp/GeoIP-1.4.8/data'
install-data-hook will not overwrite existing /usr/local/share/GeoIP/GeoIP.dat
make[3]: Leaving directory `/geotemp/GeoIP-1.4.8/data'
make[2]: Leaving directory `/geotemp/GeoIP-1.4.8/data'
make[1]: Leaving directory `/geotemp/GeoIP-1.4.8/data'
Making install in test
make[1]: Entering directory `/geotemp/GeoIP-1.4.8/test'
make[2]: Entering directory `/geotemp/GeoIP-1.4.8/test'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/geotemp/GeoIP-1.4.8/test'
make[1]: Leaving directory `/geotemp/GeoIP-1.4.8/test'
Making install in man
make[1]: Entering directory `/geotemp/GeoIP-1.4.8/man'
make[2]: Entering directory `/geotemp/GeoIP-1.4.8/man'
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/share/man/man1" || /bin/mkdir -p "/usr/local/share/man/man1"
/usr/bin/install -c -m 644 geoipupdate.1 geoiplookup6.1 geoiplookup.1 '/usr/local/share/man/man1'
make install-data-hook
make[3]: Entering directory `/geotemp/GeoIP-1.4.8/man'
cat geoipupdate.1 | sed s,DATADIR,/usr/local/share/GeoIP, | sed s,CONF_DIR,/usr/local/etc, > /usr/local/share/man/man1/geoipupdate.1
cat geoiplookup.1 | sed s,DATADIR,/usr/local/share/GeoIP, > /usr/local/share/man/man1/geoiplookup.1
cat geoiplookup6.1 | sed s,DATADIR,/usr/local/share/GeoIP, > /usr/local/share/man/man1/geoiplookup6.1
make[3]: Leaving directory `/geotemp/GeoIP-1.4.8/man'
make[2]: Leaving directory `/geotemp/GeoIP-1.4.8/man'
make[1]: Leaving directory `/geotemp/GeoIP-1.4.8/man'
make[1]: Entering directory `/geotemp/GeoIP-1.4.8'
make[2]: Entering directory `/geotemp/GeoIP-1.4.8'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/geotemp/GeoIP-1.4.8'
make[1]: Leaving directory `/geotemp/GeoIP-1.4.8'
[root@ip-12-34-567-890GeoIP-1.4.8]#
Browse to /usr/local/lib/php/extensions and look through those folders. One of them should have geoip.so in it.
When you edit your php.ini file it should have that directory listed as extension_dir. If it doesn't I'd move geoip.so to where it thinks that extension_dir is rather than changing the extension_dir to match where geoip.so is. Then you just need to make sure the lines:
extension="geoip.so"
geoip.custom_directory=/usr/local/share/GeoIP
Are added correctly to the php.ini file. If in doubt, just find that php.ini file and let it tell you where the extension dir is, rather than wading through tonnes of folders and dealing with slow SSH speeds.
zeno : the extension is in /usr/local/lib/php/extensions/no-debug-non-zts-20090626, he need to move the extension to /usr/local/lib/php/extensions
It's not simple if you don't know Unix/Linux...
To find phpize - type "which phpize".
If you still can find it, then you probably need to update your PATH in your ~/.profile to include /usr/local/bin.
Here's my .profile. Replace your current one and use this. It works everywhere:
ATH=/sbin:/bin:/usr/sbin:/usr/bin::/usr/local/sbin:/usr/local/bin:~/bin
MANPATH="/man:/usr/man:/usr/share/man:/usr/X11/man:/usr/local/man"
EDITOR=vi
VISUAL=vi
PS1="\u@\h:\w > "
export PATH MANPATH EDITOR VISUAL PS1
alias la='ls -la'
alias lct='ls -lact'
alias df='df -k'
alias du='du -sk'
alias ps='ps auxw'
alias refresh='. ~/.profile'
dos2unix () {
old=$1
new="$1.new"
tr -d '\015\032' < $old > $new
mv $new $old
}
Reload it by running the command ". ~/.profile". Later, you can accomplish the same thing by typing "refresh"
Now type "which phpize". If it's not found, it's probably not installed....
Well, the extensions can be installed anywhere. It just needs to match what's specified in /usr/local/etc/php.ini.
Specifically, you need to search and update this line in php.ini:
extension_dir = "/usr/local/lib/php/20100525"
If you change this, you'll also probably need to restart your web server.
this is all very confusing and complicated for me.. i don't have any experience with unix/linux or whatever this is. this kind of looks like DOS which i know some basic stuff in, but i'm pretty much lost. i appreciate all the effort and help from everyone though.
where i'm at now...
Zeno.. you wrote: "Browse to /usr/local/lib/php/extensions and look through those folders. One of them should have geoip.so in it. "
so i didn't see a geoip.so but i did see a libGeoIP.so which i assume may be what i'm looking for? that file is in /usr/local/lib which i also see listed in that output i pasted earlier, so i think that may be the directory i'm looking for!?
new problem is this... (of course there has to be one).. when i go to edit the php.ini file in step 7, i now get this message:
---------------------------
E325: ATTENTION
Found a swap file by the name ".php.ini.swp"
owned by: root dated: Mon Oct 15 01:10:32 2012
file name: /usr/local/lib/php.ini
modified: YES
user name: root host name: ip-12-34-567-890.ip.secureserver.net
process ID: 11578
While opening file "php.ini"
dated: Mon Oct 15 13:28:40 2012
NEWER than swap file!
(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r php.ini"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".php.ini.swp"
to avoid this message.
"php.ini" 1L, 1C
Press ENTER or type command to continue
---------------------------
when i press enter like it says, i just get a blank screen with blue squigglies on the far left of each row, nothing like what i saw before the first time with a bunch of data(?) showing. i figured out i could leave this section by hitting Esc and :wq and enter, as shown in the instructions.
i did try the :recover and vim -r php.ini but i can't seem to get back to what i saw before when it showed what looked like stuff that was supposed to be there. i know it says something about deleting the swap file but i have no idea how to find this file or even how to delete things? just figuring out how to browse directories in this place was an achievement for me..
now i'm worried i screwed up my php.ini file? is there a way to salvage this?
and zeno and hd2010, i did try to go to the directory you listed but i get this:
-bash: cd: /usr/local/lib/php/extensions: No such file or directory
update:
i figured out how to delete the .php.ini.swp file (rm .php.ini.swp) but now when i do 'vi php.ini', i get a mostly blank screen with the blue squigglies on the left side of each row, and at the bottom it shows "php.ini" 1L, 1C.
is there a way to re-generate or somehow retrieve the original php.ini file? or any advice on what i should do now?
another update:
i found out that that i was to replace line 1 with my directory as found in the "Loaded Configuration File" in step 1. i did that and i see it's different from the example given. i then did 'vi php.ini' on the file in that directory, and a bunch of stuff comes up as mentioned in the instructions.
i still don't know the correct path to plug into the 'extension dir' line as i still don't know where this geoip.so file is. i did rewrite to libGeoIP.so in my /usr/local/lib directory as a test but that didn't seem to work. how can i find out where geoip.so is?
ack.. so frustrating.. i'm thinking about just switching hosts to somewhere where their tech support would help me with this, as my current one won't.
any suggestions for where to switch to? this would be for virtual dedicated.
Well, I'm about as lost as you, difficult to understand what's happening from a distance. What hosting are you with? This is where having good hosting and a proper support team pays for itself. If you were with BeyondHosting for example you could have started a help ticket saying "please install GeoIP databases and corresponding PHP extension on my server" and you would probably get a "done" reply 5 minutes later.
Edit: post what hosting you're on, may or may not be a bad place to be for AM anyway.
i'm currently on Godaddy's virtual dedicated servers. probably not a good place to be on for AM huh?
i do know of beyond hosting from seeing them mentioned in a bunch of places but i wasn't sure if they would handle these type of issues and do x, y and z upon request but good to hear that they would. i'll seriously consider switching over to them.
thanks zeno and everyone else for sharing in this exercise in frustration with me!
The support teams are there to help you with anything that's server-side. They have no obligation to help you with any coding or site-design related things though, but those are generally easier to troubleshoot ourselves. Personally if someone gave me a server and said here, manage this for me, it would DDoS itself then burst into flames.
If you want, I'm scmtwells on skype. Give me the address and a login, and I'll fix it for you.
And yes, I'm a Unix guy with 18 years experience as a sysadmin...
And BOOM! There's your STM membership fee paying for itself.
I suggest you get a managed hosting from beyondvps, unmanaged hostng is not suitable non techy and not all system administrator knows how to optimize the software configuration for high traffic, godaddy is good for purchasing domain.
Ok, all done. I installed the GeoLite text database and cleaned up the PHP install.
First of all - while I applaud CTRtard's efforts, one must exercise caution and not blindly follow How-To instructions in the Linux world. There are so many (stupid) variations configurations between all the Linux distribution that you really need to know your system, and adapt the instructions to fit your system.
This is exactly the reason why I run FreeBSD - easy, clean, consistent, stable.
If and when you find that your traffic skyrockets and you need faster look-ups, that's when you'll upgrade to the binary install described in CTRtard's How-To.
By binary are you talking about mod_geoip, versus the pure PHP extension?
Thank you scmtwells! thanks for all your help! totally appreciated!