1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how do i properly combine Session Start and UTF-8 header

Discussion in 'PHP' started by digipointer, Jul 16, 2008.

  1. #1
    Something i never seen before happened on my hosting server.

    a couple of PHP files containing CHINESE language that i have saved in UTF-8 coding and to which i also added the usual
    <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"/>
    just keeps on dropping the UTF-8 coding at random intervals on this particular hosting server (but not on my other server).

    My PHP files start with
    PHP Session as a standalone PHP commando for the contact form.

    The hoster suggested i use the equivalent PHP header for the UTF-8 (instead of the HTTP-EQUIV) and i played around with this a bit - to no useful result.

    So i hope i find someone how could just write it out as usable copy and paste bit of code that goes on top of my .php files.
    It should simply contain the normal
    Session Start
    plus the
    header UTF-8
    and that's all.

    I hope i can then find out whether i wrote my code bit wrong or the issue is definitively server side.

    Thanks for that bit of PHP knowledge handed down:cool:
     
    digipointer, Jul 16, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    header('Content-Type: text/html; charset=utf8');
    
    PHP:
     
    nico_swd, Jul 16, 2008 IP
  3. digipointer

    digipointer Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, i knew that much, but i have to combine sessions start AND header.
    Currently i use
    <?php
    session_start();
    header('Content-Type: text/html; charset=utf-8');

    the trouble is that this works on 1 of my hosting servers - but i get error messages on another, different hosting server!

    This is why i wanted to double check with someone who knows PHP well enough to see if i have anything wrong - i personally suspect however the problem is with the PHP modules of that server where i get the error messages?????

    Thanks for fool proof clearance for me.:confused:
     
    digipointer, Jul 17, 2008 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    There isn't anything wrong with your current code. It would however help if you could post the errror you get.
     
    nico_swd, Jul 17, 2008 IP
  5. tehgamecat

    tehgamecat Peon

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Agreed, code looks correct, need to see the error really.
     
    tehgamecat, Jul 17, 2008 IP
  6. digipointer

    digipointer Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I have just changed things on the file in question back to exactly the code as i posted it in my last post and uploaded it that way for just 1 minute to copy and paste the error message.

    This is what it read
    index.php is the main page, it has indeed also a UTF-8 HEAD as in
    this index.php file can not be without UTF-8 as it is in CHINESE (the file in question, cn7g.php,
    is opening inside index.php and displays a contact form.

    See
    http://proftech.cn/
    I can also not run index.php with
    <?php session_start(); ?>
    <html>
    <head>
    <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"/>
    <meta http-equiv="Content-Language" content="cn">
    and have no UTF-8 declaration on cn7g.php, i tested that already.
    Both files need to be in UTF-8 as both contain Chinese, the contact form also to take on Chinese input to be delivered as chinese to the email.

    As mentioned, on the other server i did not get an error message, on this server i can only run both files with the HTML Meta charset
    <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"/>
    in both files, that causes no error messages and displays the foreign language right - until some fine day the UTF-8 encoding simply disapears (while no one is doing anything on the files on this strange server) - and of course the entire chinese is then nothing but "?" question marks!

    tests with
    <?php
    session_start();
    header('Content-Type: text/html; charset=utf-8');
    on at least the index.php file (where this worked) did not prevent the "dropping" of the UTF-8 encoding after an irregular amount of time either.

    Question:
    Is there anything in the coding i as a web designer can change or correct or is this - as i assume - a problem at the hosts PHP modules?:confused:
     
    digipointer, Jul 17, 2008 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    First, why don't you serve ALL your pages with utf8?

    Second, you get the error due to not running ob_start

    Before either of the lines, add ob_start();

    It let's all the info on the page be gathered before outputting anything, including headers
     
    PoPSiCLe, Jun 18, 2016 IP