PhP IP script help

  • newinvestor23
  • Born
  • Born
  • newinvestor23
  • Posts: 2

Post 3+ Months Ago

Hey all,

I am using the script below to automatically bring the user to their "home" page. I have 3 now, US which is the main page .com, CA which is canadian, .com/ca and UK, which is .com/uk
I am canadian, so it brings me to the /ca page, but when I try to goto the US main page, it will not let me, but it lets me goto the UK page. If a Canadian wanted to look in US page, I am afraid he will not be allowed, so I am looking for a script that will by pass this, or if not, at least exclude my IP address from the script, so I can actually look at the main page.
Thanks

here is a sample of the script. at the bottom, I just put in uk, ca and us as the default



Download
Contact
Sample Scripts: Country based redirection
<?php

$server = ''; // MySQL hostname
$username = ''; // MySQL username
$password = ''; // MySQL password
$dbname = ''; // MySQL db name


$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql = 'SELECT
country
FROM
ip2nation
WHERE
ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
ORDER BY
ip DESC
LIMIT 0,1';

list($country) = mysql_fetch_row(mysql_query($sql));

switch ($country) {
case 'se':
// Get the swedish to a swedish newssite
header('Location: http://www.thelocal.se/');
exit;
case 'us':
// And let the folks from american go to CNN
header('Location: http://www.cnn.com/');
exit;
default:
// The rest can go to BBC
header('Location: http://www.bbc.co.uk/');
exit;
}

?>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8399
  • Loc: USA

Post 3+ Months Ago

Can you post the actual site here?

Where is the script implemented? Is it on every page or simply on the main index page?
  • newinvestor23
  • Born
  • Born
  • newinvestor23
  • Posts: 2

Post 3+ Months Ago

It is on the main page, ****.com, in one database, I have 4 databases... this one has its own.
How would I put in php language
if ip = mine, then ignore this ..
and where in the file would I put it?
thanks again
  • cjxxi
  • Expert
  • Expert
  • cjxxi
  • Posts: 565
  • Loc: Fort Worth, TX

Post 3+ Months Ago

Code: [ Select ]
if($_SERVER['REMOTE_ADDR'] == "yourIP") {
die(' gosh this works ');
} else {

switch ($country) {
case 'se':
// Get the swedish to a swedish newssite
header('Location: http://www.thelocal.se/');
exit;
case 'us':
// And let the folks from american go to CNN
header('Location: http://www.cnn.com/');
exit;
default:
// The rest can go to BBC
header('Location: http://www.bbc.co.uk/');
exit;
}

}
  1. if($_SERVER['REMOTE_ADDR'] == "yourIP") {
  2. die(' gosh this works ');
  3. } else {
  4. switch ($country) {
  5. case 'se':
  6. // Get the swedish to a swedish newssite
  7. header('Location: http://www.thelocal.se/');
  8. exit;
  9. case 'us':
  10. // And let the folks from american go to CNN
  11. header('Location: http://www.cnn.com/');
  12. exit;
  13. default:
  14. // The rest can go to BBC
  15. header('Location: http://www.bbc.co.uk/');
  16. exit;
  17. }
  18. }

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 82 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.