heeeeeeelp unanswered open question php coding error or not?

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

  1. #1
    Hi, looks like my thread moved down and out of sight in a hurry - while i still hope for a final answer.

    Will refresh my situation shortly below, but have first 1 important issue:

    I received a PM by
    jeohfdan jeohfdan is online now
    Banned
    It says banned, and it is a junk message advertising for some gghacker.com website, something i think better no one ever clicks on it to avoid any malware etc. issues by the sound of the URL.
    The person seems to be banned already, how come he / she can still send out unsolicited PM's???
    How can i block crapsters like this from using my inbox???

    Back to my unsolved question:


    It regards how to correctly write the UTF-8 header in concunjtion with Session start at the top of my PHP files and why i would get this error message if i do it as i was told it is correctly written:
    Warning: Cannot modify header information - headers already sent by (output started at /home/proftech/www/proftech.cn/index.php:7) in /home/proftech/www/proftech.cn/cn7g.php on line 3
    index.php is the main page, it has indeed also a UTF-8 HEAD as in
    Quote:
    <?php session_start(); ?>
    <html>
    <head>
    <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"/>
    <meta http-equiv="Content-Language" content="cn">
    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?


    An additional PHP related question i would have:
    GD Lib, the thing that displays random image code for verification, can it be influenced by simply writing a bit of extra PHP code into my contact form, or is that only for the servers hosting company on their side possible??
    (what i would like to achieve is that i would get only NUMBERS in the random code, so that visitors from other countries with different alphabets could still properly verify the code).

    This is my current line of PHP code to activate the verification:
    anything in this code or additional code that would change from alphabeth and numbers to numbers only???:cool:
     
    digipointer, Jul 19, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I didn't really understand most of your post as it was just all blobbed together but I'll try to help with a couple of your problems..

    The person who sent you the PM was clearly banned after they sent you it (and they were probably banned because of the fact they sent that PM to a bunch of people). No banned people can still send PMs.

    By getting a "Cannot modify header information - headers already sent" it's telling you that it can't modify the header info (can't start the session with session_start) because you already had it send some type of content to the browser before calling it. Make sure you have NO extra white space (or anything at all) above your <?php session_start(); ?>. It's saying it's on line 3 so you must have 2 lines of something above it whether it's blank white lines or some other output.
     
    zerxer, Jul 19, 2008 IP
  3. Cri2T

    Cri2T Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    As zerxer already said, you have output being sent to the browser before the header() is being sent. This will throw the error you are getting.

    This:
    session_start();
    header('Content-Type: text/html; charset=utf-8');
    PHP:
    is wrong,

    This:
    header('Content-Type: text/html; charset=utf-8');
    session_start();
    PHP:
    is correct.
     
    Cri2T, Jul 19, 2008 IP
  4. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #4
    No, Cri2T. Doing session_start() does not count as sending output; it's also a header modifier and it's the modifier that is being errored on. He's not even setting the charset using PHP's headers; he's doing it with an HTML meta tag in the head. session_start() is the only PHP header modifier he is using and what you described wouldn't error anyways (session_start() can be above header()).

    EDIT: Well, he wasn't using header() in his one example at least. As I said I got lost in most of his post so I didn't notice the 2nd test with the header() function. Either way, the positioning of each doesn't matter. It just matters if there's something OUTSIDE of the PHP tags before it tries to modify headers (or inside the tags if you're using print/echo).
     
    zerxer, Jul 20, 2008 IP