/    Sign up×
Community /Pin to ProfileBookmark

fseek() issues | ip-to-location

I am trying to set up an ip-to-location through geoip and I cnnot get it to work for the life of me. Has anybody every tried this out and was successful? I keep getting this darn error and I even copied all the php from maxmind.com

Warning: fseek() [function.fseek]: stream does not support seeking

to post a comment
PHP

14 Comments(s)

Copy linkTweet thisAlerts:
@SrWebDeveloperOct 28.2010 — I did a little research on this, and without seeing your code, there are numerous problems and fixes. The most common is GeoIP.dat is not readable to apache/PHP or not in the right place at all, if you run a LAMP setup.

For Flash or other video streaming the error means you're trying to do can't be done with seek(). Numerous web sites dealing with this issue recommend you get all the content at once, i.e. get_file_content() then explode to make an array splitting by newlines, search and parse out what you need. In short, fseek() is not supported for the HTTP protocol as per the notes here.

Discussion on the video stream issue here

Hope this helps. You'll need to do additional research on your own.

-jim
Copy linkTweet thisAlerts:
@bradleybebadauthorOct 28.2010 — I am guessing my problem is that apache/php is not reading it (not doing streaming). I have researched it quite a bit and have seen what you are talking about with the php/apache issue. How would I make it accessible and readable? I have it in the root folder where all of my script files exist. So there shouldn't be a problem with placement, right?
Copy linkTweet thisAlerts:
@bradleybebadauthorOct 28.2010 — If I am using a LAMP setup, would you suggest uing get_file_content() instead like mentioned above?
Copy linkTweet thisAlerts:
@SrWebDeveloperOct 28.2010 — If GeoIP.dat is not readable to apache/PHP or not in the right place at all then you need to place the file in your document root or any folder within, chown it to the same user/group Apache runs and chmod 644, best guess. That's what I'd try first. Beyond that, if the issue isn't related to that it could mean use file_get_contents() and parse, instead of seek(). The links I provided details help on that issue, I've never tried it before. Best I can do.
Copy linkTweet thisAlerts:
@bradleybebadauthorOct 28.2010 — It is in the root folder. What is "chown it to the same user/group Apache runs and chmod 644?" I am kind of a newbie so this doesn't make sense to me ?
Copy linkTweet thisAlerts:
@bradleybebadauthorOct 28.2010 — This is a post I found, but I don't understand how to do it. My site is hosted by a company, so should I call them to do the server-side stuff?

I’ve recently was required to install PHP GeOIP on one of the Linux servers I do maintain here is how I did it:

  • 1. Install support for GeoIP

  • - Luckily though on Debian Linux there is a bundled deb package, so installation is trivial and clean.


  • debian-server:~# apt-get install php5-geoip

  • 2. Furthermore it’s necessery to grasp geoip’s city database


  • debian-server:~# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

  • - Extract the gz file to prepare it for use by PHP GeoIP:


  • debian-server:~# /bin/gunzip GeoLiteCity.dat.gz

  • - Move the GeoLiteCity.dat file to /usr/share/GeoIP like so:


  • debian-server:~# mv GeoLiteCity.dat /usr/share/GeoIP

    Now in order for the new geoip database to be red by PHP GeoIP we need to restart the Apache Webserver.

    debian-server:~# /etc/init.d/apache2 restart

  • 3. It’s also recommendable to update periodically the Geo IP GeoLiteCity.dat database in order to be always up-to-date with the latest IP location information provided out there, to do so I’ve created a 3 liner that does the job.


  • To start using the geoip_update.sh download it from here and set it to execute via cron.

    debian-server:~# cd /usr/sbin;

    debian-server:~# wget http://www.pc-freak.net/bshscr/geoip_update.sh

    debian-server:~# echo "02 00 1 * * /usr/sbin/geoip_update.sh >/dev/null 2>&1" | crontab -

    That’s all now PHP GeoIP database will be updated once a month on day 01 at 02:00 a.m.

    Now in order to check if your PHP GeoIP is ready to go and used by php scripts.

    Create a new sample script, let’s say check_php_geoip.php and put in it:

    <php

    print_r(geoip_record_by_name('php.net'));
    >

    Place the script somewhere under your Apache document root and invoke it via a browser, if it executes correctly you should get an output similar to:

    Array ( [country_code] => BG [country_code3] => BGR [country_name] => Bulgaria [region] => 40 [city] => Dobric [postal_code] => [latitude] => 43.5666999817 [longitude] => 27.8332996368 [dma_code] => 0 [area_code] => 0 )
    Copy linkTweet thisAlerts:
    @SrWebDeveloperOct 28.2010 — Did you follow the last two steps in the instructions? If the output was different than expected or error, tell us in detail. To answer your other question, chown and chmod are Linux commands that deal with file ownership and permissions via shell or FTP. Detailed help on each here. You can find out the Apache's user/group by looking at httpd.conf "user" and "group" settings, usually "apache" for both.

    -jim
    Copy linkTweet thisAlerts:
    @bradleybebadauthorOct 28.2010 — Btw, thanks for your help! This might help clear up things because I am a little confused on this server-side stuff. My server is hosted by bluehost and I am simply trying to load these files to the root folder and don't even know if I have access to change this sort of stuff. Does that help?
    Copy linkTweet thisAlerts:
    @SrWebDeveloperOct 28.2010 — Btw, thanks for your help! This might help clear up things because I am a little confused on this server-side stuff. My server is hosted by bluehost and I am simply trying to load these files to the root folder and don't even know if I have access to change this sort of stuff. Does that help?[/quote]


    Yes, it helps. If you have shell access, Root is one thing, document root is another. When I said document root, that means where the home page for your web site might be. Not to be confused with root which means top level root on the disk which is a more secure area (not accessible by web users). If you put it in root, and your Apache is user/group "apache", you or your webhost would:

    chown apache:apache /filename.ext

    chmod 644 /filename.ext

    I'm not sure this is even related to your issue, it was merely a common mishap based on my research. You certainly will need to do more followup on the cause of this, as I noted earlier. Wish I knew more about what you're trying to do to help based on some simple research I did to try to help.

    -jim
    Copy linkTweet thisAlerts:
    @bradleybebadauthorOct 28.2010 — Does this file mean that apache cannot read the .dat file?

    Warning: fopen(www.searchlocalinsurance.com/GeoIPCity.dat) [function.fopen]: failed to open stream: No such file or directory in /home3/circlexm/public_html/searchlocalinsurance/geoip.inc on line 357

    Can not open www.searchlocalinsurance.com/GeoIPCity.dat
    Copy linkTweet thisAlerts:
    @bradleybebadauthorOct 28.2010 — I found out that I have SSH access. If I were to put this in the root folder where my index.html is and the php file that I am trying to fopen() the .dat file with. So if that is the case, what am I doing with my SSH access to make modifications so that this will work?

    This is what my hosting company said:

    We run centOS Enterprise flavor of Linux on our servers. It is similar to RedHat Enterprise. You don't have access as the root user. You also don't have sudo access. So, you can't install things to the server such as to /usr/bin. However, with SSH access you can install things to your local account such as /home#/username/ . I don't know if GEO-IP can be installed that way or not. And, we don't really help with the installation of third party programs. You'd be on your own if you want to attempt this.
    Copy linkTweet thisAlerts:
    @SrWebDeveloperOct 29.2010 — You have limited shell access and can only upload files into your user space or web space without help from your webhost. Ugh. I now realize you didn't actually do the installation but found the instructions on how to do it from someone else.

    The instructions are for a different flavor of Linux and involves installing software within folders your webhost has told you that can't access. To overcome this you would have to first try to find a compatible binary distribution (I did, see below) and install that instead, assuming you can even install packages with your limited access. Then you would extract the GeoLiteCity.dat.gz to a folder in your home directory which you CAN access instead of the space suggested in the Debian docs and use that path instead where instructed. Plus do all the other stuff - some of which you might not even be able to do because of your limited shell, such as crontab, restarting the web server, etc.

    [COLOR=Red]All of this would require a lot of trial and error testing, and of course a solid knowledge of Linux helps to work through the many problems.[/COLOR]

    I did a quick look for a GeoIP binary for your flavor of Linux and found the following packages, to help get ya started:

    http://packages.sw.be/geoip/

    -jim
    Copy linkTweet thisAlerts:
    @inetreadyAug 17.2011 — This is a post I found, but I don't understand how to do it. My site is hosted by a company, so should I call them to do the server-side stuff?

    I’ve recently was required to install PHP GeOIP on one of the Linux servers I do maintain here is how I did it:

  • 1. Install support for GeoIP

  • - Luckily though on Debian Linux there is a bundled deb package, so installation is trivial and clean.


  • debian-server:~# apt-get install php5-geoip

  • 2. Furthermore it’s necessery to grasp geoip’s city database


  • debian-server:~# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

  • - Extract the gz file to prepare it for use by PHP GeoIP:


  • debian-server:~# /bin/gunzip GeoLiteCity.dat.gz

  • - Move the GeoLiteCity.dat file to /usr/share/GeoIP like so:


  • debian-server:~# mv GeoLiteCity.dat /usr/share/GeoIP

    Now in order for the new geoip database to be red by PHP GeoIP we need to restart the Apache Webserver.

    debian-server:~# /etc/init.d/apache2 restart

  • 3. It’s also recommendable to update periodically the Geo IP GeoLiteCity.dat database in order to be always up-to-date with the latest IP location information provided out there, to do so I’ve created a 3 liner that does the job.


  • To start using the geoip_update.sh download it from here and set it to execute via cron.

    debian-server:~# cd /usr/sbin;

    debian-server:~# wget http://www.pc-freak.net/bshscr/geoip_update.sh

    debian-server:~# echo "02 00 1 * * /usr/sbin/geoip_update.sh >/dev/null 2>&1" | crontab -

    That’s all now PHP GeoIP database will be updated once a month on day 01 at 02:00 a.m.

    Now in order to check if your PHP GeoIP is ready to go and used by php scripts.

    Create a new sample script, let’s say check_php_geoip.php and put in it:

    <php

    print_r(geoip_record_by_name('php.net'));
    >

    Place the script somewhere under your Apache document root and invoke it via a browser, if it executes correctly you should get an output similar to:

    Array ( [country_code] => BG [country_code3] => BGR [country_name] => Bulgaria [region] => 40 [city] => Dobric [postal_code] => [latitude] => 43.5666999817 [longitude] => 27.8332996368 [dma_code] => 0 [area_code] => 0 )[/QUOTE]


    I just migrated to another server and now my program is calling the following Error, which is similar to the issue I read above, am I correct?

    Warning: fopen(/usr/share/GeoIP/GeoLiteCity.dat) [function.fopen]: failed to open stream: No such file or directory in /home/syn1/public_html/admin/geoip.inc on line 357

    Can not open /usr/share/GeoIP/GeoLiteCity.dat

    According to this I need to install GEOLiteCity.dat in the Apache usr/share/GeoIP directory? How do I do this? And am I going to need to know what version of Apache I am running? I don't even know if I have GeoIP for apache installed. I am new to managing my own dedicated server and I am not getting any help from my php programmer who wrote the code, so I am having to do this myself with no Shell experience. Can you help me with the Shell commends I would need to get my GeoIp to work so my script will read it?
    Copy linkTweet thisAlerts:
    @inetreadyAug 17.2011 — I have an error similar to what you are explaining above. I migrated servers just recently and now my program that I had a developer create is not able to access the GeoLiteCity.dat Below is the error:

    Warning: fopen(/usr/share/GeoIP/GeoLiteCity.dat) [function.fopen]: failed to open stream: No such file or directory in /home/syn1/public_html/admin/geoip.inc on line 357

    Can not open /usr/share/GeoIP/GeoLiteCity.dat

    Can you help me with this? How do I fix this and upload the file to my root level apache server usr/share/GeoIP/? HELP!
    ×

    Success!

    Help @bradleybebad spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.14,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...