1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

php dev: printed text disappears (ff / ie rendering diffs?)

Discussion in 'Firefox, Thunderbird & SeaMonkey' started by osciva, 2008/09/15.

  1. 2008/09/15
    osciva

    osciva Inactive Thread Starter

    Joined:
    2008/09/15
    Messages:
    2
    Likes Received:
    0
    I've posted this question on a number of php forums with no luck, so maybe you can help me here if its a pure firefox issue?

    I have the below code. I write an encrypted message to a database. With a password sent in the url I can fetch the text from the database and print it on the screen. As soon as it is printed I want it removed from the database so it can not be fetched and read again.

    The below code works perfectly according to the above description in both internet explorer and google chrome, but in firefox the text dont get printed, or gets printed on the screen but very soon afterwards disappears, and only removed from the database.

    Since it works in ie and chome I guess it might have something to do with how firefox renders pages or executes php code? Maybe it doesn't print any values before all code is run through and then its too late because then the text is already removed from the database? I tried inserting ob_flush(), flush() and sleep(5) right after I echo the text. This prints the text even in firefox and leaves it there for the time defined in sleep(), however it is removed again as soon as the 5 seconds are over.

    Code:
    <?php
        $open = mysql_connect('localhost', 'user', 'pass');
        mysql_select_db('db');
    
        if ($_GET['m'] ==  "write "){
    
            /**
            * Write message to database
            */
            $password = md5(uniqid(rand(), true));
            mysql_query( "INSERT INTO message (message, pass) VALUES (AES_ENCRYPT('" . $_POST[ "message"] .  "','" . $password .  "'),'" . md5($password) .  "') ");
            echo  "link to message: ?p=" . $password . " ";
    
        } elseif (strlen($_GET['p']) >= 1){
    
            /**
            * Read message from database
            */
            $data = mysql_query( "SELECT AES_DECRYPT(message, '" . $_GET['p'] .  "') AS decryptedMessage FROM message WHERE pass = '" . md5($_GET['p']) .  "' ");
            $data = mysql_fetch_array($data);
            echo $data[ "decryptedMessage"];  // Prints the message on the screen
    
        } else {
            echo  "
                <FORM METHOD=\ "post\" ACTION=\ "?m=write\ ">
                    <TEXTAREA NAME=\ "message\ "></TEXTAREA>
                    <INPUT TYPE=\ "submit\ ">
                </FORM>
             ";
        }
    
        /**
        * Delete the post from the database
        */
        /**
        * The below line seems to make the text printed on the screen
        * on line 21 above disappear from the screen when using firefox
        * but it stays printed on the screen when using ie and chome
        */
        mysql_query( "DELETE FROM message WHERE pass = '" . md5($_GET['p']) .  "' ");
    
        mysql_close($open);
    ?>
    Anybody with some ideas for a solution?

    Any help is very appreciated!
     
  2. 2008/09/16
    ReggieB

    ReggieB Inactive Alumni

    Joined:
    2004/05/12
    Messages:
    2,786
    Likes Received:
    2
    Firefox does not render PHP. Neither do IE nor Chrome!

    PHP runs at the server where the server parses the PHP pages and then interprets the coding and from that generates markup code: typically HTML but could also be something else, like XML. The server then sends that resultant HTML to the client browser whether it be Firefox, IE, Safari, Chrome or Opera.

    So what Firefox is displaying is the HTML generated by the server running PHP.

    You seem to be dumping text with little HTML formatting. I expect that Firefox is struggling because the text isn't coming out where you are expecting it within the HTML document.

    Try installing the Firefox HTML validator extension. That should make it easy for you to search through the HTML that is actually getting to your browser. I expect it will highlight the code you are having a problem with and tell you what it doesn't like about it.
     

  3. to hide this advert.

  4. 2008/09/16
    osciva

    osciva Inactive Thread Starter

    Joined:
    2008/09/15
    Messages:
    2
    Likes Received:
    0
  5. 2008/09/16
    ReggieB

    ReggieB Inactive Alumni

    Joined:
    2004/05/12
    Messages:
    2,786
    Likes Received:
    2
    By the way. Your code is wide open to being hacked.

    For example, if someone enters the message:
    Code:
    text', 'text'),'text'); DROP TABLE message;
    and adds "?m=write" to the URL, your message table will be deleted.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.