Code Organisation

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Plxply
Forum Newbie
Posts: 14
Joined: Sat Dec 19, 2009 2:40 pm

Code Organisation

Post by Plxply »

Hello,

This is a slightly strange question so bare with me. I've been dabbling in PHP for a while and to help further my PHP skills I created a basic URL shortening service with a login and registration system, this works fine however I'm not sure I organised it in the best manner.

What I basically did was have an if statement at the top of the page which would check for example if the username field has been posted if not it would run:

Code: Select all

include_once("interface/login.php");
die();
interface/login.php will contain the HTML for the login interface along with parts of the code that was ready to accept errors e.g.

Code: Select all

<body><?php if(isset($pass_error)) { echo $pass_error; }?>
Then within the login.php code I would compare the hashed password with the one in the database if it did not match I would then run code similar to this:

Code: Select all

$pass_error = "<div class='error'>You have entered an incorrect username/password</div>";
include_once("interface/login.php");
die();
However I'm not sure if this is the most "clean" way of handling it and I would appreciate if someone would tell me better ways in which I can structure my code and the interface for it.

Thank you,
Post Reply