Install GeoIP on PHP

Hello,

i had to check which country some visitors come from when visiting a website and i remembered that awstats (statistik tool) uses a plugin called GeoIP. But awstats is written in perl and i asked myself if the extension does not exist for php and guess what: it exists! Here is a small howto to install it on CentOS:

I found GeoIP in a third-party repository named EPEL. Check here if you want to now how to install the repository. So now to the installation:

# yum install gcc php-pear geoip geoip-devel
# pecl install geoip

After that you only have to add following line to your php.ini or create geoip.ini in your php.d directory with following content:

extension=geoip.so

Now restart the webserver and you are good to go. Only one note left: geoip is compiled with your actual running php version, so if you upgrade it you have to recompile your geoip installation.

more infors about the geoip functions can be found here.

Joomla 1.0 and PHP 5.3

hi all of you,

i've just tried to migrate a Joomla 1.0 site to a server running php 5.3. After migrating the files and database i wanted to check the site and bam, guess what? errors…

If you get some errors similar to this one

Warning: Parameter 1 to HTML_content::show() expected to be a reference, value given in /home/xx/public_html/travel/includes/Cache/Lite/Function.php on line 92

it's because Joomla 1.0 is not compatible with php 5.3. The fix is quite simple: add a for-loop to the Function.php file (beginning of the call-function) and everythng runs again. Here the code:

<?php

$arguments = func_get_args();
$numargs = func_num_args();
for ($i = 1; $i < $numargs; $i++) {
   $arguments[$i] = &$arguments[$i];
}

?>

source: http://www.asim.pk/2010/01/13/joomla-does-not-support-php-5-3/

Howto open, read and write a file in PHP

Hello world,

this is a very basic operation which i do almost every day and of course you can do it in different ways like always in programming. It's however not for absolute beginners. You need to have some basic knowledge about variables, functions etc. Please visit php.net for these basics, their online documenttation is one of the best of all languages i've worked with.

here is an example how you could do it:

<?php

# OPEN A FILE IN READ ONLY AND PUT RESULT INTO A FILE HANDLER ($FH)
$fh = fopen("/tmp/openme.txt", "r");

Possibiliy 1:

# READ CONTENT AS ONE BIG TEXT STRING FROM FILE HANDLER
$content = file_get_contents($fh);

Possibility 2:

# READ FILE AS AN ARRAY (EVERY LINE GOES TO ONE ARRAY ENTRY)
$content = file($fh);

# IF READ AS AN ARRAY YOU NEED FIRST TO CONVERT THE
# ARRAY INTO A STRING BEFORE SAVING
$content = implode("", $content);

# CREATE A NEW FILE OR OPEN FILE IN WRITE MODE AND GIVE IT
# A NEW FILE HANDLER ($FH_NEW)
$fh_new = fopen("/tmp/saveme.txt", "w");

# NOW STORE THE CONTENT IN THERE
fwrite($content, $fh_new);

# AND DO NOT FORGET TO CLOSE THE FILE AFTERWARDS TO MAKE YOUR FILE PERMANENT
fclose($fh_new);

?>

So, that's it. Hope this helped some of you people out there.