- Messages
- 1,682
- Reaction score
- 32
- Points
- 48
I have a language selection which first sees if $_GET['lang'] is set, or a cookie is set.
the commented part, is code i've taken from a tutorial here on x10, can't get a link to it right now though. but it worked without the header error.
the error i get is:
which happens to be this line:
here is part of the page calling it:
config.php
connect.php
so after all that heap of code, can anyone make heads or tails of why it won't allow me to set a cookie. because i like cookies and its bad if I can't have one. xD
PHP:
<?php
if (!defined('ROOT'))
die;
$text['english'] = "English";
$text['trad-chinese'] = "中文";
// here you add the languages.
ob_start();
global $defaultLang;
/*
if(isset($_GET['lang'])) {
require $_GET['lang'] . ".php";
setcookie("saveLang", $_GET['lang'], time()+3600*24*30, '/'); // cookie that will expire in 1 month
} else if(isset($_COOKIE["saveLang"])) {
require $_COOKIE["saveLang"] . ".php";
} else if(!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
require $defaultLang .".php";
setcookie("saveLang", $defaultLang, time()+3600*24*30, '/');
} else {
$language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$language = substr($language,0,2); // splitting languages....
if(( $language == "en") or ( $language == "tch")) { // checking if language is valid .. here you can change or add the languages
require $language. ".php";
setcookie("saveLang", $language, time()+3600*24*30, '/');
} else {
require $defaultLang . ".php";
setcookie("saveLang", $defaulLang, time()+3600*24*30, '/');
}
}
*/
// CHECKS AND MAKES THE LANGUAGE SELECTION A GLOBAL VARIABLE ALONG WITH A YUMMY COOKIE
if(isset($_GET['lang'])) {
if(file_exist($_GET['lang'].'.php')) {
$language = $_GET['lang'].'php';
} else {
$language = $defaulLang;
}
} elseif(isset($_COOKIE["saveLang"])) {
$language = $_COOKIE["saveLang"];
} else {
$language = $defaultLang;
}
setcookie("saveLang", $language, time()+3600*24*30, '/');
define('LANG', $language);
//BRINGS IN THE LANGUAGE FILES
require ROOT.'sources/language/'.LANG.'.php';
ob_end_flush();
?>
the commented part, is code i've taken from a tutorial here on x10, can't get a link to it right now though. but it worked without the header error.
the error i get is:
Code:
[B]Warning[/B]: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\mcs\connect.php:11) in [B]C:\xampp\htdocs\mcs\sources\language\setlanguage.php[/B] on line [B]47[/B]
which happens to be this line:
PHP:
setcookie("saveLang", $language, time()+3600*24*30, '/');
here is part of the page calling it:
PHP:
require_once ROOT.'config.php';
require_once ROOT.'sources/language/setlanguage.php';
require_once ROOT.'sources/functions/home.php';
include ROOT.'sources/functions/gallery.php';?>
config.php
PHP:
<?php
if (!defined('ROOT'))
die;
/* DB Connection */
$dbName = '';
$dbUsername = '';
$dbPassword = '';
$dbPort = '';
include ROOT.'connect.php';
/* IMPORTS */
// include ROOT.'sources/functions/functions.php';
$defaultLang = "en";
date_default_timezone_set('');
define ('HTTPDIR', '');
?>
connect.php
PHP:
<?
// connect to the database server
if (!($db = mysql_pconnect($dbPort, $dbUsername , $dbPassword))){
die("Can't connect to database server.");
}else{
// select a database
if (!(mysql_select_db($dbName, $db))){
die("Can't connect to database.");
}
}
?>
so after all that heap of code, can anyone make heads or tails of why it won't allow me to set a cookie. because i like cookies and its bad if I can't have one. xD