HTML/PHP show IMG based on location


 
Thread Tools Search this Thread
Top Forums Web Development HTML/PHP show IMG based on location
# 1  
Old 02-26-2012
HTML/PHP show IMG based on location

HI guys/gals,

I like to add some personal touches to a welcome image on our mediawiki site, and have the welcome be displayed in the, presumed, language of the visitor.

Standard would be English, but if the IP or browser or OS is set to be in India, I want to display the message in Urdu for example... Or if South Afrika than I want the SA Afrikaans image to show.

Anyone have some idea on how to accomplish this using simple code?
# 2  
Old 02-26-2012
What web server are you running? Apache2?

If running Apache, you can install the GeoIP Apache API.
# 3  
Old 02-26-2012
Hi,
Thank you for the kind reply,

Yes its an HTTPD (Apache2) server.

I see that using this package I could rewrite some stuff,
but how would I change a simple

HTML Code:
<img src="usaimage" alt="usa image"  />
And apply geo coding to it

HTML Code:
if
geo code is USA display <img src="usaimage" alt="usa image"  />
if
geo code is INDIA display <img src="indiaimage" alt="india image"  />

Last edited by lawstudent; 02-26-2012 at 03:58 AM.. Reason:  
# 4  
Old 02-26-2012
Did you look at the examples in the link provided?

In PHP, you would do something like:
PHP Code:
$country_code apache_note("GEOIP_COUNTRY_CODE");

if(
$country_code == 'US')
    
$image '/images/usimage.jpg';
elseif(
$country_code == 'IN')
    
$image '/images/india.image.jpg';
else
    
$image '/images/default.jpg'
If you want to embed PHP in your HTML, you can search the web on how to do this.
# 5  
Old 02-26-2012
Wow,
I must have missed that, its exactly what I need!
Thank you so much Neo!
# 6  
Old 02-26-2012
You are welcome!

There is plenty of info and examples here.

Pure PHP README:

[QUOTE]Requirements

None (only the 'GeoIP.dat' file is needed). To download a free GeoIP Standard Country
database, go to

http://maxmind.com/download/geoip/database/

Install

Just place the 'geoip.inc' file somewhere according to the 'include_path' directive of
your 'php.ini' file, or just place it in the same directory as your PHP scripts.

Usage

Gets country name by hostname :

include("geoip.inc");

$gi = geoip_open("/usr/local/share/GeoIP/GeoIP.dat",GEOIP_STANDARD);

echo geoip_country_code_by_addr($gi, "24.24.24.24") . "\t" .
geoip_country_name_by_addr($gi, "24.24.24.24") . "\n";
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";

geoip_close($gi);

Memory Caching:
To enable memory caching, pass GEOIP_SHARED_MEMORY or
GEOIP_MEMORY_CACHE to the second argument of geoip_open

For GEOIP_SHARED_MEMORY, requires php >= 4.0.4,
and --enable-shmop passed at configure time, see
http://us2.php.net/manual/en/ref.shmop.php
In addition, you should call geoip_load_shared_mem
before calling geoip_open. See sample_city.php for an
example of shared memory caching.

Working with PHP5.
geoip_country_code_by_addr should work
with PHP.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Apache configuration Automation based on location

Hi I need to find a way to automate the deployment of my apache configuration to a few servers. I make change frequently on apache/conf/... etc, and I usually do this manually by copying files to each servers(and country config path)and restart apache servers.Source file will be like... (1 Reply)
Discussion started by: naresh2389
1 Replies

2. Shell Programming and Scripting

Show Logs from a server location to a web browser

hey Guys, Am a newbie to Linux and have a probable requirement that might come up pretty soon. I need to understand, how log files and log location can be displayed on a web browser. So that the end user can read the log files and should be able to search for order numbers in the logs. If... (2 Replies)
Discussion started by: ashish_samarth
2 Replies

3. Shell Programming and Scripting

How to copy files from one location to another based on a priority?

Hi Gurus, I am a newbie to shell scripting and I am facing a problem right now.I have to automate the copy of files based on a priority.The scenario is as below: 1) There will be files from Mon-Fri with Mon file being named as abc_def_01_YYYYMMDD and Tue file being abc_def_02_YYYYMMDD and so... (4 Replies)
Discussion started by: vikramgk9
4 Replies

4. Shell Programming and Scripting

Parse based on location

I do have a big text file >A1 ACFGTSDCHG_GDF DGHA >A2 A_FGGSD_HG_GSF DGTA >A3 AC_GSDD_TU_GDF DGH_ .. ... there are equal number of characters within all the sub-headers. I want to parse out all the characters under each sub-header from user specified locations. For example, I want... (5 Replies)
Discussion started by: Lucky Ali
5 Replies

5. Web Development

PHP client location based page loading

Hi, I am new to PHP and at first got a task where I need some clues and help. So I am here.. The server is build to provide customized access for modules as per location. If client location is US then it shows modules and pages specific to US and if location is UK then it shows UK specific... (1 Reply)
Discussion started by: zing_foru
1 Replies

6. OS X (Apple)

Location Based Printing in Leopard not working

Hello all, I've been searching for an answer but coming up with nothing so I figured I'd give it a shot and ask. After installing a fresh version of Leopard (with the latest updates) on a computer and then copying the user data back onto said computer, the location based printing doesn't work... (0 Replies)
Discussion started by: erodrigue
0 Replies

7. Shell Programming and Scripting

how to detect ip address based location using PHP

I am interested in finding out if there is a reliable and economical way for extracting user's location based on his ip address, using php I tried to get the job done using ip2location.com, but I am not happy how it deals with result inconsistently. (2 Replies)
Discussion started by: siftin-com
2 Replies

8. UNIX for Dummies Questions & Answers

copying files from one location to another based on a list

I have a text list of about 3,000 file names (image files), which exist on a server and that I want to copy over to another location. I understand the Unix cp code, but what's the string to have it copy multiple files based on an external list? Many thanks! (4 Replies)
Discussion started by: rebornhonest
4 Replies
Login or Register to Ask a Question