Sytem login with php

Good afternoon.

I have questions about the login system that has bothered me for quite some time. For this, I want you to imagine that I have 2 pages login.phpand userpage.php. The page logincontains fields for entering a username and password. While userpagecontains all the information about the registered user. When a user enters his data, some class Connectionchecks it in the database and, if the user exists, creates a session.

  • When I create a redirect from login.phpto userpage.php, how do I redirect user data? (Should I use global arrays (e.g. $_SESSION) to transmit information, or should I reconnect db from the user page?)

  • Do I have to create some multithreading (not to judge strictly, I'm a beginner) for userpage.phpwhich will be created for several users who are trying to log in at the same time?

  • How to protect information (code side) so that it is difficult to read? (For example, the source code on Facebook pages, because I don’t want some β€œbad guys” to browse my sources) and other things.

  • How can I make some users see what others cannot? For example, it userpage.phpshows different links and information for different users and all the information for me.

  • How can I prevent viewing membership.php? (Is there any other way besides using header?)

  • How can I deny viewing requireboth require_oncein login.phpand userpage.php?

+4
source share
3 answers

1.) When I create a redirect from login.php to userpage.php, how do I redirect user data? (Should I use global arrays (e.g. $ _SESSION) to transfer information, or should I reconnect db from the user page?)

You need to have a db connection every time you want to get user data. You can create a session to store a unique attribute for the user, for example $_SESSION['id'], when the user is successfully registered, and you can use this value on any page to query db and obtain the necessary user data.

2.) ( , ) userpage.php, , ?

, . . , . (, . , ;))

3.) ( ), ? (, Facebook, , " " ) .

- , html css, , javascript. php . " " , db, php- ..

4.) , ? , userpage.php .

. , , db, , . ,

    if ($user['permission']==1)
        // Show something
    elseif ($user['permission']==2)
        // show something else

5.) member.php? ( , ?)

- , , , :

    if (!isset($_SESSION['id']))
        header("Location: login.php");

6.) , require_once login.php userpage.php?

, , : require require_once - , , . , , " ", - . 3.

:

, , . , . - , , . , , , , . , .

+4
+3

, , , , .

, .

  • SESSION . SESSIONS. userpage.php. , , .
  • SESSION COOKIE . / . .
  • PHP . javascript css -u . .
  • . , $_SESSION['admin'] =true / userpage.php.
  • , NEXT
  • , ? HTML/JS, . if-else ur php- , header.php, , require require_once.

. , / framweorks. !

wrt . , , / , .

-

index.php
    |--action    
         |---register.php
         |---logged_in_user_landing.php
  • index.php. .  , ​​ .

    If yes, action/logged_in_user_landing.php else include action/register.php.

    if-else .

  • register.php . submit index.php ( ).

  • establish a db connection on the index page and check the combination of username and password. If correct, set SESSION for this user and enable "action / logged_in_user_landing.php".

  • Have a unique identifier sent when redirecting from each individual page. So that you can determine what to do in index.php.

This is a very simple architecture that needs to be run. This is a kind of controller-based architecture and will help you in the future when you enter the MVC architecture.

+1
source

Source: https://habr.com/ru/post/1540183/


All Articles