Jump to content

Correct coding style


irken

Recommended Posts

Hello.

I'm pondering weather I should (and can, legally) do like below, or if I should use 'print' to display the HTML code. The below workes fine, but that's not a reason for it to be correct :-). Thank you for reading.

[code]
<?php

    // Start/resume session.
    session_start();
   
    // username
    if (!$_SESSION['navn'])
    {
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Login</title>
</head>
<body>
    <form action="checklogin.php" method="post">
        <p>
            <input id="txtNavn" type="text" name="Navn" /><br />
            <input id="txtKode" type="password" name="Kode" /><br />
        </p>
        <input id="btnLogin" type="submit" value="Login" />
    </form>
</body>
</html>

<?php
    }
    else
    {
        echo 'Logout before logging in again.';
    }
?>
[/code]
Link to comment
Share on other sites

PHP is designed so that you can enter and exit PHP coding as often in your script as you'd like. I don't know if there will be problems with the blank space or not as roopurt18 says (I'm not saying he's wrong, I'm just saying I don't know), but you can use PHP only where needed or you can use it for all output or technically you could even generate no output via PHP and just name your HTML pages as PHP pages (though this doesn't make any sense there shouldn't be any adverse effects to doing so). ;)
Link to comment
Share on other sites

[quote author=roopurt18 link=topic=118518.msg484329#msg484329 date=1166044960]
... that IE will choke on that empty line between your ?> and <!DOCTYPE
[/quote]

Hmm. I've not experienced that myself - but you might be right. I'm using IE 7 and so far no problems. I'd really love to be able to make these kind of spaces too, because I've got such a weak spot for clean looking code :-).

I'll have to try it out in older versions of IE, altho I was thinking of just limiting access for IE browser 6 and above. I really don't have the heart, not "skills" to figure out all the different ways these browsers parses things. Firefox acts way differently than IE. Which of them are not following the official guidelines ?  :D
Link to comment
Share on other sites

I don't think any one browser sticks entirely to the standard, though I know that IE definitely has quite a bit of IE-specific coding specifications that most other browsers will not render properly. FF tends to have less of this. But if you want to be sure you should check the W3's verification tools. Those will define the official standard.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.