Jump to content

PHP Login class and one more question


Julius

Recommended Posts

Hello,

 

I'm doing something that looks like framework. It's my first serious "project". And now, I have a few questions: what basic functions are needed in MVC model class? Just tell me some functions, that could use, so I could try to code them. And the next question is... I'm going to create a login system for users. In my website there will be pages, that are visible for all visitors, and only for members. For example main website page should be visible for all visitors, but the page, where member can change his password, should be visible only for member. I know only one way to do this: allways and everywhere check if user is logged in. But isn't there smarter and simpler way?

 

I hope you understood what I need. Sorry for bad english

Link to comment
Share on other sites

In my website there will be pages, that are visible for all visitors, and only for members. For example main website page should be visible for all visitors, but the page, where member can change his password, should be visible only for member. I know only one way to do this: allways and everywhere check if user is logged in. But isn't there smarter and simpler way?

 

What is not simple/smart about checking if a user is logged in before displaying pages that require the user to be logged in? If you are storing a flag in the $_SESSION variable it is a simple task to check. Just include a file at the top of every page that requires the user to be logged in. That file would check if the user is logged in. If not, that file will redirect them to the login page and cancel execution of the rest of the script (which would have displayed the page requiring the user to be logged in).

Link to comment
Share on other sites

this is a very good solution, BUT. My file starts like this: <?php Mynewclass extends Controller { function () { code } } ?>, so how should I include that file, or maybe you could give me an alternative solution? OOP is new for me, just started using. And my "framework" is pretty similar to codeigniter

Link to comment
Share on other sites

I would make a new file called: checkuser.php

in checkuser.php (you can also directly input this in all the pages you want to check user)

<?php

include('-the-place-you-have-stored-the-class-file.php');

$checkuser = new nameoftheclass();

$checkuser->name-of-the-function-under-the-class();

?>

 

Please correct me if i'm wrong, i'm new to PHP too.

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.