• I need to include a bit of php code as the very first line on my blog pages. This code triggers a membership login and needs to appear before doctype on the page (I know this is not good coding, but I have no choice but to do it this way at the moment). I placed the at the top of the header.php file of my theme; however, two things are going on. 1. I cannot see the code when I view the page source (which seems odd to me) and 2. Regardless of not being able to see it in page source, the script does appear to be triggering in IE and Chrome, but not in Firefox. Am I doing this wrong by adding it to the header.php file? Any thoughts are appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Why do you say the code has to be above the DOCTYPE?

    Thread Starter srower

    (@srower)

    Yes, as I stated, I know it’s wrong and if I didn’t have to do it, I wouldn’t be asking for assistance. It involves a programmer hired by a client who has created a total mess for me to work with, but I have no choice at the moment. The only way to get what he did to work is to put this code before DocType. Any assistance to accomplish this would be great. Thanks.

    1. I cannot see the code when I view the page source (which seems odd to me)

    You cannot view the PHP code by doing a view source because PHP is executed on the server. For example, if you write this PHP code:

    <?php
    echo "Hello world!";
    ?>

    All you are going to see when you do a view source is Hello world!.

    2. Regardless of not being able to see it in page source, the script does appear to be triggering in IE and Chrome, but not in Firefox.

    Again, PHP executes on the server, so it doesn’t matter which browser the user is using. The output created by the PHP may be rendered differently on different browsers, especially if there is something wrong with what is being generated. I usually find that Chrome is more forgiving than Firefox when an ending paragraph tag or an ending DIV tag is left off.

    Can you paste a sample of the PHP code that’s supposed to go before the DOCTYPE? If it’s too long, put it into a pastebin and provide a link.

    Thread Starter srower

    (@srower)

    Thanks so much for the response. The code is simple:
    <?php require_once(‘enable_protection.php’); ?>
    which triggers a script file in the same directory.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding php code before DocType’ is closed to new replies.