phpeeved Posted October 13, 2013 Share Posted October 13, 2013 Hey guys, currently working on a project for school where we are building a small web application, very basic stuff... Login page, different accounts, some uploading and really just trying to keep things dynamic while utilizing a flat file database... I have a question with regards to the login page. I always hear more experienced developers telling me to keep things modular. I am trying to have my logic and data seperated, and I will be building a lot of functions for this site. However, the functions are for things that I will be calling I'm various areas of the page. The login though, is just a single instance on the first page the users come to. In your guys experience, would you create a login function? Or just code it right at the top of the login page? Any input you guys have would be greatly valued. Thanks for your time, J Quote Link to comment Share on other sites More sharing options...
vinny42 Posted October 14, 2013 Share Posted October 14, 2013 In your guys experience, would you create a login function? Or just code it right at the top of the login page? If you put everything else in functions then why make a n exception for the login? And are you sure that the login code will only ever be used on the login page? But think about testing also; you cannot easily automatically test PHP code that is embedded in a piece of HTML, while it's very easy to execute a function and see if it returns true or false. Quote Link to comment Share on other sites More sharing options...
Benny150592 Posted October 14, 2013 Share Posted October 14, 2013 You should always use functions and make things modular wherever you can. It just makes life easier in the long run! Quote Link to comment Share on other sites More sharing options...
phpeeved Posted October 15, 2013 Author Share Posted October 15, 2013 If you put everything else in functions then why make a n exception for the login? And are you sure that the login code will only ever be used on the login page? But think about testing also; you cannot easily automatically test PHP code that is embedded in a piece of HTML, while it's very easy to execute a function and see if it returns true or false. I cant think of any other instances where I will have to use the log in code again, so I was just wondering if that what the basis on knowing whether or not you should make a function for it. Thanks for your guys response, I will turn my login code into a function now. Quote Link to comment Share on other sites More sharing options...
vinny42 Posted October 15, 2013 Share Posted October 15, 2013 I cant think of any other instances where I will have to use the log in code again, so I was just wondering if that what the basis on knowing whether or not you should make a function for it. Functions enable code re-use, so in the most strict sense that is the criterium; no re-use: no function. But in modern programming you always have at least two uses: once in your application and once in your unittests. Logging-in of course ican be re-used all over the place; on the main login form, but also in login popups that appear when you visit a bookmarked page inside the restricted area, in datafeeds, basically in every situation where you ned to access restricted data while you're not logged in. Quote Link to comment Share on other sites More sharing options...
ale8oneboy Posted October 15, 2013 Share Posted October 15, 2013 Something to think about when deciding to use functions or not - Ask yourself: "Am I about to cut and paste a block of code?" The response should be: "Then maybe I should turn this block of code into a function." Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.