Irish SEO,  Marketing & Webmaster Discussion
 
nominate sites now!
 

Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 26-03-2008, 05:50 PM
Cormac's Avatar
Cormac Moylan
 
Join Date: Jan 2006
Location: Baile Ath Cliath / Corcaigh
Posts: 1,174
Cormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to behold
Send a message via AIM to Cormac Send a message via MSN to Cormac Send a message via Yahoo to Cormac Send a message via Skype™ to Cormac
Default php redirect based on browser language

Hi guys,
I have the following script which should redirect a user if they are using a Polish browser to a specific page. I have asked a Polish friend to test it using his Polish version of Firefox but he said he didn't work. Here is the code:

PHP Code:
<? 
function redirect()
  {
  
$lang $_SERVER['HTTP_ACCEPT_LANGUAGE'];

    switch(
$lang){
        case 
'pl':
            
$redir_url "http://www.google.pl";
            break;
        default:
        case 
'en':
            
$redir_url "http://www.allotherbrowsers.com/landingpage.php";
            break;
    }
    
header("Location: $redir_url");
}
redirect();


?>
He says he gets brought to allotherbrowsers.com/landingpage.php instead of google.pl

Can anyone spot the problem?
__________________
my blog | Apple Mac Blog | Indie Music Blog | *

Last edited by Cormac; 26-03-2008 at 05:52 PM.
Reply With Quote
  #2 (permalink)  
Old 26-03-2008, 05:56 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 1,923
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

did you try echo the result to see what's going on?
PHP Code:
function redirect()
  {
  
$lang $_SERVER['HTTP_ACCEPT_LANGUAGE'];
echo 
$lang; exit();//comment this when finished
 
    
switch($lang){
        case 
'pl':
            
$redir_url "http://www.google.pl";
            break;
        default:
        case 
'en':
            
$redir_url "http://www.allotherbrowsers.com/landingpage.php";
            break;
    }
    
header("Location: $redir_url");
}
redirect(); 
__________________
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Directory Submission Directory Submission
:. News & Press Release Ireland GiveItSocks.com
:. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories
:. I Have 2 Find It Directory SEF Directory
Reply With Quote
  #3 (permalink)  
Old 26-03-2008, 08:12 PM
Cormac's Avatar
Cormac Moylan
 
Join Date: Jan 2006
Location: Baile Ath Cliath / Corcaigh
Posts: 1,174
Cormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to behold
Send a message via AIM to Cormac Send a message via MSN to Cormac Send a message via Yahoo to Cormac Send a message via Skype™ to Cormac
Default

the echoed result is - pl,en-us;q=0.7,en;q=0.3

That agent seems a bit odd. I downloaded the Polish version of Firefox myself to test. I opened a browser-language.php file in the browser and it displayed the following information - Mozilla/5.0 (Macintosh; U; Intel Mac OS X; pl; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13

I'm stumped!
__________________
my blog | Apple Mac Blog | Indie Music Blog | *
Reply With Quote
  #4 (permalink)  
Old 26-03-2008, 08:26 PM
Cormac's Avatar
Cormac Moylan
 
Join Date: Jan 2006
Location: Baile Ath Cliath / Corcaigh
Posts: 1,174
Cormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to beholdCormac is a splendid one to behold
Send a message via AIM to Cormac Send a message via MSN to Cormac Send a message via Yahoo to Cormac Send a message via Skype™ to Cormac
Default

I tired some alternative code and it works:
PHP Code:
<?php 
$lang 
= ($_SERVER['HTTP_ACCEPT_LANGUAGE']); 

if(
ereg("pl"$lang)) { 
    
header("location: http://google.pl"); 
} else { 
    
header("location: http://google.com"); 

?>
__________________
my blog | Apple Mac Blog | Indie Music Blog | *
Reply With Quote
  #5 (permalink)  
Old 26-03-2008, 08:56 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 1,923
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

of course it does because ereg looks for the match (in this case "pl") and if found returns true.
You can also use preg_match which is faster as it's Perl-compatible.
__________________
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Directory Submission Directory Submission
:. News & Press Release Ireland GiveItSocks.com
:. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories
:. I Have 2 Find It Directory SEF Directory
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ruby on Rails VS PHP Code Igniter gav240z Coding Help 10 03-02-2008 11:04 PM
Browser based calling ... dbee The Business Aspects of Web Work 1 21-09-2007 11:01 AM
Updating a php based site from any computer ciller Webmaster Discussion 4 19-06-2007 06:56 PM


All times are GMT +1. The time now is 01:57 AM.


Powered by: vBulletin Version 3.7.2, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.

Search Engine Friendly URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56