Dashboard, Secure Page & Logout | CMS Tutorial Part 5

Поделиться
HTML-код
  • Опубликовано: 20 фев 2023
  • In this tutorial we'll create dashboard, secure page and logout page.
    Part VI: • User Management CRUD |...
    Make sure to subscribe & ring a bell 🔔 to get notified about new lessons.
    📰 Source code: github.com/mdbootstrap/knowle...
    ______________________________________
    📰 If you prefer written tutorials, you will find 25+ lessons on Bootstrap here - mdbootstrap.com/learn/mdb-fou...
    ______________________________________
    📥 MDB UI KIT FREE download - mdbootstrap.com/
    💎 MDBootstrap Pro - mdbootstrap.com/docs/standard...
    📤 FREE hosting - mdbgo.com/
    ______________________________________
    👨‍👩‍👧‍👦 If you have any questions - don't hesitate to ask on our Facebook group:
    / 682245759188413
    ⭐ Support the creation of open-source packages with a STAR on GitHub
    github.com/mdbootstrap/mdb-ui...
    _______________________________
    Table of Contents
    00:00 Start coding

Комментарии • 13

  • @WolfTheGamer27
    @WolfTheGamer27 Год назад +2

    Hi got a quick question. When we set message to welcome new user is it recommended to do it like you via php echo? Or pass it to JS and display it through that? I always have problem separating what should be done by JS and what my PHP. Any advice in that matter? Thanks in advance :D

  • @tomaszklekner9879
    @tomaszklekner9879 Год назад

    For all the people learning PHP, the $_SESSION undefined issue can be solved by doing what Harry Disseldorp suggested, or you need to include session_start(); in the start of every script that uses the $_SESSION variables.

  • @TheLightningRick
    @TheLightningRick 2 месяца назад

    I think can all agree that with building this that we all just want to die(); 🤣🤣

    • @Mdbootstrap
      @Mdbootstrap  2 месяца назад +1

      😂😂😂

    • @TheLightningRick
      @TheLightningRick 2 месяца назад

      @@Mdbootstrap I need some help the secure(); function isn't working properly I have it set like this.
      function secure() {
      if (!isset($_SESSION['id'])) {
      set_message('Please Login First to View this Page');
      header('Location: /cms');
      die();
      }
      }
      but whenever I log in it doesn't allow me to reach the dashboard without sending me back to main screen with the message "Please Login First to View this Page" I do not know what to do because everything works perfectly when I do not add the secure(); function to dashboard.php and I always put the secure(); on the 6th line of the dashboard.php like this
      just like that do you know what I may be doing wrong?

    • @TheLightningRick
      @TheLightningRick 2 месяца назад

      @@Mdbootstrap nevermind I figured it out I changed
      function secure() {
      if (!isset($_SESSION['id'])) {
      set_message('Please Login First to View this Page');
      header('Location: /cms');
      die();
      }
      }
      to this right here and it worked
      function secure() {
      if (!isset($_SESSION['email'])) {
      set_message('Please Login First to View this Page');
      header('Location: /cms');
      die();
      }
      }
      now my page is secured I'm super happy

    • @Mdbootstrap
      @Mdbootstrap  2 месяца назад +1

      @@TheLightningRick
      Session Start: Make sure you have called session_start(); at the beginning of your PHP script before any output is sent to the browser. This should be done in each PHP file where you intend to use or set session variables. If you haven't started the session, the $_SESSION['id'] will not be recognized across different pages. Your config.php, database.php, or functions.php might be a good place to include session_start();, ensuring it executes before anything else.
      Session Variables: Double-check the logic where you set $_SESSION['id']. Make sure this is happening as expected when a user logs in. You should ensure that this part of your code is being executed and that the $_SESSION['id'] is correctly set upon successful login.
      Cookies and Browser Issues: Sometimes session issues can be related to cookies not being set correctly in the browser. Ensure your browser accepts cookies, and try clearing your browser's cookies and cache. Also, try using a different browser or a private/incognito window to see if the problem persists.
      File Includes: Make sure that the order and presence of includes do not affect session management. Although it doesn't seem like the issue comes from here, it's always good to double-check that includes/config.php, includes/database.php, and includes/functions.php don't have output before session_start() or conflicting session management logic.
      Session Path or Configuration Issues: Check your PHP server settings and ensure that the session save path is writable and not causing issues. Sometimes session data can fail to save due to permission issues on the server.
      Debugging: You can add debugging information before the redirect to see what’s going on. For instance, you could add var_dump($_SESSION); die(); before the header('Location: /cms'); line in your secure() function. This will show you what's currently in the session and might help you identify why $_SESSION['id'] isn't set as expected.
      Path and Redirection: Ensure that the path you are redirecting to ('/cms') is correct and accessible. If there's a misconfiguration in your directory structure or .htaccess file, it might be causing unexpected behavior.
      In your dashboard.php, before calling secure(), there shouldn't be any problem but ensure that session_start(); is being called appropriately before this. If session_start(); is in one of your included files, make sure it's getting executed before secure();.
      If none of these steps resolve the issue, consider reviewing the login logic to ensure $_SESSION['id'] is being set correctly upon a successful login, and there are no other conditional redirects that might be interfering.
      Give us a message how it went, I hope it helps :)

    • @TheLightningRick
      @TheLightningRick 2 месяца назад

      @@Mdbootstrap well I did $_SESSION[‘email’] and it worked perfectly with the secure function also I finished the series today and successfully built a fully functioning CMS so thank you so much your videos really helped me a ton

  • @hwcjdisseldorp
    @hwcjdisseldorp Год назад +2

    Hello Michal, first I want to complement you about this excellent course. However, I have a question about the global $_SESSION variable. I entered the same code as in the course but got the same error as (currywurstboi 420). An undefined variable _SESSION warninig. The only way I can get it to work is to add a session_start() call at the top of each page. Can you explain why your version is working and ours isn't.

    • @hwcjdisseldorp
      @hwcjdisseldorp Год назад +5

      Hello Michal, just want to let you know, that I found out to set the session.auto_start variable in the php.ini file to 1 solves the problem.

  • @currywurstboi4202
    @currywurstboi4202 Год назад +1

    Mad probs for your tutorials, I really appreciate them.
    Unfortunally I run into an issue... If I set var_dump($_SESSION) in dashboard.php I get an undefined variable warning and NULL.
    Every step before works fine. It seems that my SESSION data wont be sent.
    Checked everything twice ... What could be my mistake?

    • @hwcjdisseldorp
      @hwcjdisseldorp Год назад +2

      Hello, I just found out how you can make it work. In the php.ini file you set the 'session.auto_start' to 1.