www.webdeveloper.com
Results 1 to 7 of 7

Thread: [RESOLVED] Cookie problem with Yii framework.

Hybrid View

  1. #1
    Join Date
    Mar 2013
    Posts
    19

    resolved [RESOLVED] Cookie problem with Yii framework.

    I'm using Yii framework.
    I set a cookie as you can see blow , it was working in localhost but stop working after I uploaded my web app on online host. I'm getting this error:
    Cannot modify header information - headers already sent by (output started at <path to webapp>/protected/components/Controller.php:1)

    Code:

    PHP Code:
    class Controller extends CController
    {
       public function 
    changeLanguage()
            {
                if(isset(
    $_GET['language']) && $_GET['language']=='fa'){
                    
                
    $cookie = new CHttpCookie('language','fa_ir');
                        
    $cookie->expire time()+60*30;
                        
    Yii::app()->request->cookies['language'] = $cookie
    How can I set a cookie in header? Why it was working on localhost?

  2. #2
    Join Date
    Mar 2013
    Posts
    19
    I use this function as a filter for all actions.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,388
    Make sure that the /protected/components/Controller.php file does not have anything on line 1 that causes output. One possibility is that you have a BOM (byte order mark) or any other white-space character before the <?php tag. (Make sure your FTP client is not inserting anything, perhaps?)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Mar 2013
    Posts
    19
    I use Cpanel to upload web app and I'm sure files are the same and without any change. Even I changed my code with one of Yii's extensions to do this work but I got same error in line of setting cookie again.

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,388
    output started at <path to webapp>/protected/components/Controller.php:1
    This is telling you that something sent output to the client at line 1 of Controller.php. To fix this problem, you either have to figure out what was generating that output and fix it so it no longer does, or else before that file gets invoked, turn on output buffering (either in your php config file, or else via ob_start() in any file -- if there is one -- that gets invoked prior to that file.

    I'm still placing my bet on a BOM.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Mar 2013
    Posts
    19
    YOU WON!
    I had changed encoding some of files using Dreamweaver to utf-8. It had added some invisible characters to begin of files. It solved by using ob_start() in Yii config file.
    For more information see this: http://www.yiiframework.com/forum/in...rect-problems/

    Thank you for your help. Encoding problems make white some of my hairs occasionally!

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,388
    For future sanity and fewer gray hairs, check to see if DW has an option to save UTF-8 files without a BOM.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles