User identity, access SESSION in php

Hello All,

I’m trying for a long time now to build a cms handling users/roles/pages etc…

I thing I am on a very good stage and I have managed to finally do it but now I am on the stage to restrict page access/permissions based on users roles.
This brought me back a few steps back because I have to build in php all the needed SC I have already made.
Again, that’s fine but I am stuck on zero point because I can’t retrieve the user ID…
I have tried already:

  • security provider name “scname”.
  • <?php echo $_SESSION['scnameId'] ?>

Not working… Getting:
Notice : Undefined variable: _SESSION in xxxxxxxxxxxx\index.php on line 49
Notice : Trying to access array offset on value of type null in xxxxxxxxxxx\index.php on line 49

I cannot figure what I am doing wrong…
Please, somebody have a suggestion?

Thanks in advance

Wappler 5.5.1
PHP, mySQL

Maybe this will help you.

and

and instead of using * <?php echo $_SESSION['scnameId'] ?> use the Security Identity via server connect.

Thanks @Mozzi for replying.

I have successfully accomplished all these steps and procedures…

I am talking on accessing user ID and building server actions (queries,checks and outputs) on server side (php , pdo() )

Well just add the identity step in the globals and it will be accessible in the data picker in all your server actions.

Dear @Teodor,

I am talking about server side coding…
Line number 1 in my page

Server side coding in Wappler is happening in the Server Connect panel. You don’t need to use php code on your pages.

I am talking about something similar…

Am I wrong?

What are you trying to achieve exactly that is not possible with the server side tools in Wappler, that requires php coding on the pages?

Every page will be rendered If a user has access to this page…

And this is already possible using security provider and security provider enforcer within Wappler.

dear @Teodor please understand me… Then I should give wappler to the administrators of the site and give them lesson on how to use it…

Not sure i understand what you mean by this.

When building a site with Wappler you can simply use the security provider enforcer which places the required code on your page to restrict access and not render the content to not authorized users.

Why are you using Wappler at all in case you want to hand code your site?

OK brother, thanks for your time.
I will restrict page permissions by security provider enforcer panel.

By the way, in case I need it, how can I access the user ID in server side? Is there a way?

Thanks again but as I already have mension it is not woking for me…
Anyway, I may have to search somewhere else to find the answer

It is not working as you didn’t include

<?php
    session_start();
?>

on your page.
Again, it would save you all of these issues if you use the components in Wappler and not hand-coding it. that’s the idea of using Wappler.

1 Like

THANK YOU BROTHER!!!

And I thank you for two reasons…

  1. You solved the reason that my initial thread was about - session_start() was missing.
    It didn’t work anyway because when I included session_start() I got a:
    Notice : Undefined index: scnameId
    (Maybe because I used an example provider name in my thread “scname”, the actual name is “sc_name”. This underscore symbol maybe?)

  2. Your insistence pointed me to the right direction, no hard coding…
    And this direction came up from this post of yours:
    Wappler Documentation - Show or Hide Elements Conditionally
    I will set a variable to “hide”. I will hide all of my content in the main div and set it as conditional region, its condition will be my variable == “show”.
    Now, on my original SC I added a success event that a) set variable=“show” b) if SC gives permission a browser.goto (same page) but ticked internal otherwise browser.goto(login or index)

I hope I can make it happen (without hard-coding thanks to you).

Chears