PhP IP script help

  • newinvestor23
  • Born
  • Born
  • No Avatar
  • Joined: Jan 13, 2009
  • Posts: 2
  • Status: Offline

Post January 13th, 2009, 9:20 am

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
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post January 13th, 2009, 9:20 am

  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post January 14th, 2009, 5:39 pm

Can you post the actual site here?

Where is the script implemented? Is it on every page or simply on the main index page?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • newinvestor23
  • Born
  • Born
  • No Avatar
  • Joined: Jan 13, 2009
  • Posts: 2
  • Status: Offline

Post January 16th, 2009, 6:34 pm

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
  • No Avatar
  • Joined: Aug 02, 2004
  • Posts: 564
  • Loc: Fort Worth, TX
  • Status: Offline

Post January 16th, 2009, 11:46 pm

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. }
networklatino.com
-----------------------------------

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: Bigwebmaster and 121 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
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.