+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Another one of those header output problems.

  1. #1
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Another one of those header output problems.

    I have a language selection which first sees if $_GET['lang'] is set, or a cookie is set.
    PHP Code:
    <?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"$languagetime()+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:
    Warning:  Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\mcs\connect.php:11) in C:\xampp\htdocs\mcs\sources\language\setlanguage.php on line 47
    which happens to be this line:
    PHP Code:
    setcookie("saveLang"$languagetime()+3600*24*30'/'); 
    here is part of the page calling it:
    PHP Code:
    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 Code:
    <?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 Code:
    <?
    // 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

  2. #2
    lhyman's Avatar
    lhyman is offline x10 Sophmore lhyman is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    198

    Re: Another one of those header output problems.

    That happened to me once, I had to run:

    http://localhost/xampp/splash.php


    again and set the lang to english and then all the header errors went away

    (This should reset the cookie)
    My Name is Larry Hyman from Montreal. I fix computers on site, see my web site for more details:

    http://hyman.sytes.net

  3. #3
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: Another one of those header output problems.

    nope, nothing happened

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Another one of those header output problems.

    If any of the files you include before you try to send headers has a space after a closing

    ?> 'invisible' space here

    that will cause the problem.
    Nothing is always absolutely so.

  5. #5
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: Another one of those header output problems.

    thank you descalzo,
    had a space in the connect.php line 11. these little things catch you off guard

    but now a new problem has arisen (sp?):
    I set $lang if it checks and passes to a DEFINE

    PHP Code:
    define('LANG'$language);

    //BRINGS IN THE LANGUAGE FILES
    require ROOT.'sources/language/'.LANG.'.php'
    but for some reason, LANG is just being pulled in as nothing, so I end up getting a error not found error.

  6. #6
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Another one of those header output problems.

    Can you set a constant with a variable in PHP?
    Nothing is always absolutely so.

  7. #7
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: Another one of those header output problems.

    o I didn't even think about it like that.
    I wish there is a way you can,
    for some reason I just like the way the constant looks, it can be global and you don't need a $ sign

  8. #8
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Another one of those header output problems.

    Quote Originally Posted by descalzo View Post
    Can you set a constant with a variable in PHP?
    Yes.

    @diabolo: Make sure $language and $defaultLang are set.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  9. #9
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: Another one of those header output problems.

    PHP Code:
    if(isset($_GET['lang'])) {
       if(
    file_exists($_GET['lang'].'.php')) {
          
    $language $_GET['lang'];
       } else {
          
    $language $defaulLang;
       }
    } elseif(isset(
    $_COOKIE['saveLang'])) {
       
    $language $_COOKIE['saveLang'];
    } else {
       
    $language $defaultLang;

    can anybody seem to get this, because it looks alright to be
    but for some reason $language is not registering.
    and $defaultLang is set in config.php

  10. #10
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Another one of those header output problems.

    Quote Originally Posted by diabolo View Post
    PHP Code:
    if(isset($_GET['lang'])) {
       if(
    file_exists($_GET['lang'].'.php')) {
          
    $language $_GET['lang'];
       } else {
          
    $language $defaulLang;  <<<<<<<<<<<<<<<<<<<<<<<<
       }
    } elseif(isset(
    $_COOKIE['saveLang'])) {
       
    $language $_COOKIE['saveLang'];
    } else {
       
    $language $defaultLang;

    can anybody seem to get this, because it looks alright to be
    but for some reason $language is not registering.
    and $defaultLang is set in config.php
    Dropped a t
    Edit:
    Quote Originally Posted by misson View Post
    Yes.
    Ok. Was asking as much as stating. Most languages don't allow you to it.
    Last edited by descalzo; 08-26-2009 at 09:53 PM. Reason: Automerged Doublepost
    Nothing is always absolutely so.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. PHP header() problems
    By Harlan in forum Programming Help
    Replies: 7
    Last Post: 02-28-2009, 10:05 AM
  2. Header Output Errors
    By jjpeacha in forum Programming Help
    Replies: 4
    Last Post: 09-14-2008, 06:56 PM
  3. Header Location Problem
    By xevell in forum Free Hosting
    Replies: 7
    Last Post: 07-15-2008, 09:28 PM
  4. domain available again
    By Uchiha Sasuke in forum Free Hosting
    Replies: 17
    Last Post: 03-06-2008, 01:34 PM
  5. cant access website
    By Uchiha Sasuke in forum Free Hosting
    Replies: 5
    Last Post: 02-28-2008, 02:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers