This topic is locked
[SOLVED]

 Using Security API outside Main Directory

5/10/2020 4:15:06 AM
PHPRunner General questions
W
WisTex author

How do you access the Security API (or otherwise check who is logged in) outside the PHPRunner directory structure?
For example, if the PHPRunner generated script is in the /dashboard subdirectory, how do files in the main / directory check to see if anyone is logged in?
We have included:

<?php include("/dashboard/include/dbcommon.php"); ?>


We have tried the following:

$userData = Security::isLoggedIn();

var_dump($userData);



$userData = Security::getUserName();

echo $userData;
echo $_SESSION["UserID"];



None of the above produce any values.
These work if we test them in the /dashboard directory, but none of these work when placed in the / directory.
How do we access the UserId and Username? If possible how do we get the primary key (an integer) from the user table for the currently logged in user?

Sergey Kornilov admin 5/11/2020

Maybe instead of

include("/dashboard/include/dbcommon.php");



try

include("dashboard/include/dbcommon.php");


Also, you need to be logged in to the PHPRunenr app for Security API to work.

W
WisTex author 5/11/2020



Maybe instead of

include("/dashboard/include/dbcommon.php");



try

include("dashboard/include/dbcommon.php");


Also, you need to be logged in to the PHPRunenr app for Security API to work.



Thank you for that correction. I just tried that and am getting a result now, but I am getting conflicting results.
If I run the following code in /dashboard/test.php

include("include/dbcommon.php");

$userData = Security::isLoggedIn();

var_dump($userData);



It returns bool(true) and provides the user information (when calling additional variables).
But if I run the following code in /test.php

include("dashboard/include/dbcommon.php");

$userData = Security::isLoggedIn();

var_dump($userData);



it returns bool(false) even though you are logged into the script located in /dashboard
I also tried accessing other variables, and it appears it is detecting that you are logged in if the script is in the /dashboard (PHPRunner) folder, but not outside of it. Unless I have another typo.

W
WisTex author 5/11/2020

Okay, I figured it out.
The code for the include file MUST be on the very first line for it to work. You cannot put anything before it at all, not even white space. Otherwise, you get a "Cannot modify header information" error.
Error:

Warning: Cannot modify header information - headers already sent by (output started at /.../test.php:1) in /.../dashboard/include/dbcommon.php on line 51


But placing the following code on the VERY FIRST LINE will work. It won't work anywhere else in the file.

<?php include("dashboard/include/dbcommon.php"); ?>


Amazing how a little white space before the include can crash the whole thing.