Current location: Hot Scripts Forums » Programming Languages » PHP » Redirection tweak.


Redirection tweak.

Reply
  #1 (permalink)  
Old 05-02-05, 02:25 PM
mickalo's Avatar
mickalo mickalo is offline
Newbie Coder
 
Join Date: Apr 2005
Location: N.W. Iowa
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Redirection tweak.

Hello,

was hoping to get a little help on a PHP script we download, from http://hot-things.net/ip2c.php for redirection for multiple language sites.

ip2c is a PHP script which is able to determine to which country an IP address belongs, redirect to the proper page in a multilanguage site. There is a redirect.php script that redirects which works fine, but we have mutliple subdomains, and it doesn't quiet work the way we hoped. Hopefully someone maybe fimilar with this script. I am by no means a PHP programmer, strickly perl So my knowledge is very limited and was hoping with good PHP experience could possibly lead a helping hand with this.

Basically what we have is a main domain: www.somedomain.com and if the person hits the site from the US or UK, they would be redirected to: uk.somedomain.com but what this redirect script does is redirect to www.somedomain.com/uk which works but we want to redirect to the actual subdomain: uk.somedomain.com

if you can help out with this, would be much appreciated. I can send you the script to look at. Please PM or email me at: mickalo@thunder-rain.com

Any help would be greatly appreciated.

Mickalo
__________________
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
Custom Perl Programming & MySQL designs
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Reply With Quote
  #2 (permalink)  
Old 05-02-05, 02:40 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
i havent looked at the script but find the bit where it says:

header ("Location: URL");

and change the URL!
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #3 (permalink)  
Old 05-02-05, 03:07 PM
mickalo's Avatar
mickalo mickalo is offline
Newbie Coder
 
Join Date: Apr 2005
Location: N.W. Iowa
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by FiRe
i havent looked at the script but find the bit where it says:

header ("Location: URL");

and change the URL!
I wish it was the simple

I'm playing with it alittle more too see what I can do with it. it's just doesn't seem recongize subdomains structures, as it reads the server directories to see if the country folder exists, IE "uk" folder then just appends that to the main domain, instead of redirecting to the actual subdomain.

thx's for help tho,
Mickalo
__________________
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
Custom Perl Programming & MySQL designs
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Reply With Quote
  #4 (permalink)  
Old 05-02-05, 03:50 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

//assuming $country is set to uk or whatever the ip location is


if (file_exists("$country/index.php")) {
header ("Location: http://$country.site.com");
}
else {
header ("Location: http://www.site.com");

__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #5 (permalink)  
Old 05-02-05, 04:02 PM
mickalo's Avatar
mickalo mickalo is offline
Newbie Coder
 
Join Date: Apr 2005
Location: N.W. Iowa
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by FiRe
PHP Code:

//assuming $country is set to uk or whatever the ip location is


if (file_exists("$country/index.php")) {
header ("Location: http://$country.site.com");
}
else {
header ("Location: http://www.site.com");

well the way it actual works, I think!!, it's reading the server directory paths in relationship to where this redirect.php is located, then detects whether or not the folder (the country 2 letter abbr.), like 'uk' exists off of the server doc., root. But as I say, I'm not a php programmer. I can do this with Perl I'm sure, but this is not my project

Be happy to post the script or send it too you if you'd like to take a look-see and maybe give me some insight how to fix it

TIA,
Mickalo
__________________
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
Custom Perl Programming & MySQL designs
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Reply With Quote
  #6 (permalink)  
Old 05-02-05, 06:58 PM
Anastas Anastas is offline
Wannabe Coder
 
Join Date: Mar 2005
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Just post it here and/or emailing it to me ( anastas @ promethian.info ) and I'll try to help out if I can.
Reply With Quote
  #7 (permalink)  
Old 05-02-05, 07:11 PM
mickalo's Avatar
mickalo mickalo is offline
Newbie Coder
 
Join Date: Apr 2005
Location: N.W. Iowa
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Anastas
Just post it here and/or emailing it to me ( anastas @ promethian.info ) and I'll try to help out if I can.
here is the script
Code:
<?php

$crdr='./ip2c'; // set a correct RELATIVE path to the directory where the db files are ('.'=current, no tralilng slashes)


function set_path($cc){return "$cc";}
/*
use the function 'set_path()' to set a correct relative path to a file or directory where the user must be redirected
do NOT touch $cc - it's 2-letters country code
do NOT use trailing slashes
examples:
  function set_path($cc){return "$cc";} - will redirect to a directory called 'uk', 'ru', 'fr' etc
  function set_path($cc){return "index-$cc.php";} - will redirect to a file called 'index-uk.php', 'index-fr.php' etc
  function set_path($cc){return "../index-$cc.php";} - will redirect to a file called 'index-uk.php', 'index-fr.php' etc BUT one level up
*/ 


$default="uk";
/*
set a link to redirect users if the returned from the function 'set_path()' path is not valid.
examples:
1) IF function set_path($cc){return "$cc";} AND $default="uk";
   and you have only 'uk' and 'fr' directories, people from Turkey (there's no directory for them) will be redirected to the English one - 'uk'
2) IF function set_path($cc){return "index-$cc.php";} AND $default="index-uk.php";
   and you have only 'index-uk.php' and 'index-fr.php' files, people from Turkey (there's no file for them) will be redirected to the English one - 'index-uk.php'
*/


$pv=phpversion();$pv=substr($pv,0,1);if($pv>3){$REMOTE_ADDR=$HTTP_SERVER_VARS['REMOTE_ADDR'];}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><title><?php print $SERVER_NAME; ?></title>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<script type="text/javascript"><?php
$v=0;$f=0;$n=array();$ip=$REMOTE_ADDR;

$ip=sprintf("%u",ip2long($ip));
while(strlen($ip)<10){$ip='0'.$ip;}
$h=opendir($crdr);
while($e=readdir($h)){
$o=(int)$e;if(strlen($o)>5){
$n[$f]=$e;$f++;}}closedir($h);
sort($n);

$o=count($n)-1;$d=$n[$o];
for($j=0;$j<$o;$j++){if($ip>=$n[$j]&&$ip<$n[$j+1]){$d=$n[$j];break;}}

$d=$crdr.'/'.$d;$q=fopen($d,"r");
while(!feof($q)){$r=fgets($q,32);
$a=substr($r,0,9);$b=substr($r,10,19);$c=substr($r,20);
if($ip>=$a&&$ip<=$b){$v=1;break;}}
fclose($q);

if($v==0){print "window.location='$default'";}
else{$cc=strtolower($c);$cc=str_replace("\n","",$cc);
$path=set_path($cc);
if(is_file($path)||is_dir($path)){print "window.location='$path'";}
else{print "window.location='$default'";}}
?></script></head><body></body></html>
if you have questions, let me know.

appreciate any help or suggestions!
Mike
__________________
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
Custom Perl Programming & MySQL designs
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Reply With Quote
  #8 (permalink)  
Old 05-03-05, 02:45 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
LMAO how easy to read
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CE7.net - Free phpBB & Invision Forums, cPanel hosting and Redirection pcpp General Advertisements 0 04-29-05 07:01 AM
Setting up Redirection Script SQL help Seben PHP 5 08-29-04 10:43 AM
javascript redirection based on referring URL andyinorbit2000 Script Requests 1 05-31-04 01:56 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 06:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.