Forum Moderators: coopster
I tried this code; but it won't work & it screws up the wordpress & show's errors?
<? $user_lan = $HTTP_ACCEPT_LANGUAGE; if($user_lan=='zh-sg') {
## Singapore
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='zh-mo') {
## Macau SAR
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='zh-hk') {
## Hong Kong SAR
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='zh-cn') {
## China
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='zh-tw') {
## Taiwan
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='zh') {
## Chinese
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='ja') {
## Japanese
$redir_url = "http://www.domain.com/japanese.html";
} elseif($user_lan=='ko') {
## Korean
$redir_url = "http://www.domain.com/korean.html";
}
header("Location: $redir_url");
exit;
?>
note that the pages/domains being redirected to are not the same domain that the code is placed on.
I placed the code in the head tag, it did not work, so I tried in the body tag & it did not work. all I get are wordpress display errors.
if you are going to use the header function then you need to this before any output is sent to the browser. I would suggest doing this first, before anything else happens.
above the html, no white spaces before your <?php tag because even that causes your headers to be sent to the browser.
thank you, but this didnt work either? Is there something wrong with the code?
I put it at top of page before all the html, etc, & then when go to load page I get page can not be found, so it's definitly not working.
so I moved it to right above the header info, & get this on the page;
Warning: Cannot modify header information - headers already sent by (output started at /usr/www/virtual/user/www.domain.com/wp-content/themes/themename/header.php:3) in /usr/www/virtual/user/www.domain.com/wp-content/themes/themename/header.php on line 39
Warning: Cannot modify header information - headers already sent by (output started at /usr/www/virtual/skull/www.domain.com/wp-content/themes/themename/header.php:4) in /usr/www/virtual/skull/www.domain.com/wp-content/themes/themename/header.php on line 105
I've tried pretty much ever possible spot & not one of them work.
<html><head>
<?php header("Content-type: text/plain"); ?>
<title>
...
Wrong! Cannot output headers after you've already starting writing hmtl!
space character here, or even just a newline
<?php header("Content-type: text/plain"); ?>
...
Wrong again! Cannot output headers after you've already starting writing hmtl! In this case, the blank space or even something as simple as a newline is considered output. You will get an error.
Somewhere in your code, prior to your header() function, you are outputting something. You will have to find it.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11"><title><?php bloginfo('name');?> <?php if ( is_home() ) {?>» <?php bloginfo('description');?><?php }?> <?php wp_title();?></title>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type');?>; charset=<?php bloginfo('charset');?>" />
<meta name="generator" content="WordPress <?php bloginfo('version');?>" />
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url');?>" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url');?>" />
<link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url');?>" />
<link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url');?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url');?>" />
<?php wp_get_archives('type=monthly&format=link');?>
<?php wp_head();?>
<meta name="keywords" content="keywords deleted">
<META NAME="Author" CONTENT="author">
<META NAME="copyright" content="September 2005">
<META HTTP-EQUIV="imagetoolbar" CONTENT="no">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
<META NAME="robots" content="index,follow">
<meta http-equiv="revisit-after" content="3 days">
<META NAME="Description" CONTENT="content">
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" L gen true for "http://www.domain.com" r (SS~~000 9 SS~~001 2 SS~~002 7 SS~~003 2 SS~~004 7 SS~~009 1))'>
<link rel="meta" href="http://domain.com/labels.rdf" type="application/rdf+xml" title="ICRA labels" />
<SCRIPT LANGUAGE="JavaScript">
if (navigator.appName == 'Netscape')
var language = navigator.language;
else
var language = navigator.browserLanguage;
if (language.indexOf('zh') > -1 ¦¦ language.indexOf('zh-cn') > -1 ¦¦ language.indexOf('zh-hk') > -1 ¦¦ language.indexOf('zh-mo') > -1 ¦¦ language.indexOf('zh-tw') > -1 ¦¦ language.indexOf('zh-sg') > -1)
document.location.href = 'http://www.domain.be/China/chinese.html';
</script></head>
<body><script type='text/javascript' src='http://track.mybloglog.com/js/jsserv.php?mblID=#*$!xxxx'></script>
<div id="wrapper">
<div id="header">
<div id="title">
<h1><a href="<?php echo get_settings('home');?>"><?php bloginfo('name');?></a><br><div align="center"><a href="http://www.link.com"><img src="/flag_ja.gif" alt="link info" width="18" height="12" border="0"></a> <a href="http://www.link2.htm"><img src="/flag_ko.gif" alt="link 2" width="18" height="12" border="0"></a> <a href="http://www.link3.html?ref=xxxx"><img src="/flag_zh-CN.gif" alt="link3" width="18" height="12" border="0"></a></div></h1>
</div>
</div>
I placed the php redirect at the top;
like this;
<? $user_lan = $HTTP_ACCEPT_LANGUAGE; if($user_lan=='zh-sg') {
## Singapore
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='zh-mo') {
## Macau SAR
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='zh-hk') {
## Hong Kong SAR
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='zh-cn') {
## China
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='zh-tw') {
## Taiwan
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='zh') {
## Chinese
$redir_url = "http://www.domain.com/chinese.html";
} elseif($user_lan=='ja') {
## Japanese
$redir_url = "http://www.domain.com/japanese.html";
} elseif($user_lan=='ko') {
## Korean
$redir_url = "http://www.domain.com/Korea.htm";
}
header("Location: $redir_url");
exit;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<title><?php bloginfo('name');?> <?php if ( is_home() ) {?>» <?php bloginfo('description');?><?php }?> <?php wp_title();?></title>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type');?>; charset=<?php bloginfo('charset');?>" />
<meta name="generator" content="WordPress <?php bloginfo('version');?>" />
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url');?>" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url');?>" />
<link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url');?>" />
<link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url');?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url');?>" />
<?php wp_get_archives('type=monthly&format=link');?>
<?php wp_head();?>
<meta name="keywords" content="keywords deleted">
<META NAME="Author" CONTENT="author">
<META NAME="copyright" content="September 2005">
<META HTTP-EQUIV="imagetoolbar" CONTENT="no">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
<META NAME="robots" content="index,follow">
<meta http-equiv="revisit-after" content="3 days">
<META NAME="Description" CONTENT="content">
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" L gen true for "http://www.domain.com" r (SS~~000 9 SS~~001 2 SS~~002 7 SS~~003 2 SS~~004 7 SS~~009 1))'>
<link rel="meta" href="http://domain.com/labels.rdf" type="application/rdf+xml" title="ICRA labels" />
<SCRIPT LANGUAGE="JavaScript">
if (navigator.appName == 'Netscape')
var language = navigator.language;
else
var language = navigator.browserLanguage;
if (language.indexOf('zh') > -1 ¦¦ language.indexOf('zh-cn') > -1 ¦¦ language.indexOf('zh-hk') > -1 ¦¦ language.indexOf('zh-mo') > -1 ¦¦ language.indexOf('zh-tw') > -1 ¦¦ language.indexOf('zh-sg') > -1)
document.location.href = 'http://www.domain.be/China/chinese.html';
</script></head>
<body><script type='text/javascript' src='http://track.mybloglog.com/js/jsserv.php?mblID=xxxxxxx'></script>
<div id="wrapper">
<div id="header">
<div id="title">
<h1><a href="<?php echo get_settings('home');?>"><?php bloginfo('name');?></a><br><div align="center"><a href="http://www.link.com"><img src="/flag_ja.gif" alt="link info" width="18" height="12" border="0"></a> <a href="http://www.link2.htm"><img src="/flag_ko.gif" alt="link 2" width="18" height="12" border="0"></a> <a href="http://www.link3.html?ref=xxxx"><img src="/flag_zh-CN.gif" alt="link3" width="18" height="12" border="0"></a></div></h1>
</div>
</div>
this did not work; so I then tried placing it after the closing div at the end, & this did not work...
it was at the top, there are no spaces or lines before the <? & yes it was in header.php which IS the first file to be parsed, as index php is created by combination of header.php, sidebar.php, main.php, page.php, search.php, archives.php, etc, etc, etc...
index.php can not exist without header.php being first because header.php is the top of the page before the content, & header.php contains the head & the meta, therefore it is always first & always on top.
index.php is not an editable file.
regardless of where you think it is
everytime you get this
>> headers already sent bythen something is being output first, that is exactly what the error means, yelling at people and rudeness don't change this fact
First of all, I don't hear a single sound on this board, so I can not possibly be yelling, 2, you do not know me, therefore you can not call me rude.. What did I do to cause such response. I have not yelled or been rude to anyone. But now I will be rude in response to your incorrect accusation to me,, since your such a smart guy ,, explain to me why this code ALONE ON A SINGLE PAGE BY ITSELF gives the SAME ERROR & THERE IS NO HEADER TO OUTPUT. Matter of fact, the code alone on a page has nothing at all to output?
Even on non wordpress page with no other code, it is producing the same result.
when I comment out the header line and echo $user_lan I get
en-us,en;q=0.5
so it won't work for me anyway but it does make me think that the value of $user_lan might be a little different than your script expects.
so are you getting another warning or error aside from the headers already sent? If so that the first warning would cause the headers error.