Go Back   Free website templates > Web Template Help > PHP and MySQL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Join now to download all the free website templates or post on the forum. If you have never been on a forum before read the FAQ. It's quick, easy and free to join!
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-27-2008, 06:40 PM
vareside's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 254
vareside is on a distinguished road
Post PHP Country-Message

Hi folks,
I need a PHP script which identifies the users location and displays a predefined message that depends on the country.

Tutorials, links, snippets and hints are welcome.

Max
Reply With Quote
  #2 (permalink)  
Old 06-29-2008, 02:16 AM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,360
ishkey will become famous soon enough
Default

function getRealIpAddr(){ if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip;}

In this PHP function, first attempt is to get the direct IP address of client’s machine, if not available then try for forwarded for IP address using HTTP_X_FORWARDED_FOR. And if this is also not available, then finally get the IP address using REMOTE_ADDR.

second part could be repeated for each page you need:

if($_SERVER['REMOTE_ADDR']=='999.999.999.999')
{
Redirect the user to http://my page.com
}
else
{
Load my page
}

This sould be an easy method that should work, but wantabe hackers could cause a problem with “HTTP_” headers. In that they can easily be faked by the client. I could make your function belive I have any address, simply by sending it an X-Forwarded-For header.
__________________
RIF= Reading Is Fun - Understanding Funner
cleandeck - lawn mower undercoating and wilmargraphite - graphite lubricants
Reply With Quote
  #3 (permalink)  
Old 06-29-2008, 11:39 AM
vareside's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 254
vareside is on a distinguished road
Default

But I'm looking for something like the javascript over here:
http://www.vareside.com/portal/sidebar.js
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:02 AM.



mouseover mouseover mouseover