Jump to content
xisto Community
yeska

Q: User Login

Recommended Posts

With 'function', do you mean a php function that generated all the html code and then spits it out ?Don't know if this could give you any advantage over a static page as a login page is a static page. It's better to have static page with some javascript to make it a bit more dynamic ;)

Share this post


Link to post
Share on other sites

You would really need to weigh the Pros or Cons. However, even if one doesn't outweigh the other doesn't mean you should not use it.Myself personally, everything I do requires a class, whether it's spitting out pages or verifying authenticity, I'll make it a class. You don't want to be working on static pages, because every time you want something to change, you'll need to upload the whole page over and over, if you made it dynamic, send a few simple commands to your script and it's done for you.Just make use of what technology is available to you and use it to it's fullest extent.Cheers,MC

Share this post


Link to post
Share on other sites

I would say it is a matter of site traffic. If you aren't expecting a high volume of traffic through your website then I would recommend using your own custom function/class however, high volume traffic sites such as web communities and forums then static pages are a better way of reducing the pressure on your web server.

I've never agreed with using classes and functions for every single aspect of your sites design. It may seem all neat and tidy, but it can really start chewing up those cpu cycles. A seperate include containing php classes and functions that you feel will be used in more than one place on your site is efficient, however if you are only going to use the function once and nowhere else on the site then definately just write it in to the page as raw php and don't bother putting it in a class or function.

At this point I'm hearing programmers screaming in my ear NOOOOO however it is a cold hard fact this is what is best for your server even if it is not the best for you.

Also the advantage of doing this is if you suddenly realise you are going to need to use this function in more places on your site, it's a simple matter of extracting the raw php, modifying it a little bit and putting it in your general functions include and replacing the code with the new function.

I once saw an example of a login site which was absolutely ridiculous. The entire thing, and I mean the ENTIRE thing was a series of custom functions. It nearly made me sick going through it all. If you need to put multiple html outputs in to a single php document then it is a hell of a lot easier to seperate them like this:

<?phpif ($_GET['page'] == 'login'){?>Login page goes here<?php}elseif ($_GET['page'] == 'register'){?>Registration page goes here<?php}elseif ($_GET['page'] == 'logout'){?>Logout page goes here<?php}else {?>Home page goes here<?php}?>

A lot less pressure on your server yet still divided out in to manageable and none confusing sections that you can work on without a high chance of messing up and getting lost in an ocean of code.

Alternatively you could have a central control document like the one above and call in your seperate pages using a page activation variable and a series of includes like so:

<?php$pageactivate = true;if ($_GET['page'] == 'login'){include('login.php');}elseif ($_GET['page'] == 'register'){include('register.php');}elseif ($_GET['page'] == 'logout'){include('logout.php');}else {include('home.php');}?>

Then your seperate php files can contain the following to ensure they are only being access by the above page and not manually typed in to the browser:

<?phpif ($pageactivate == true){?>Page content goes here<?php}else {header('Location: index.php');exit;}?>

Really, structuring your site like this is just as tidy as having all your own functions and classes in one file, that's why file systems haven't changed much since they were first created. People get over excited about different filing methods though and tend to take it to extremes.
Edited by 8ennett (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.