custom php page not working

karen

Member
I have created a custom php page named testpage.php, but cannot get it to display.

If I add it to custom pages as a php file, with the source file referenced, when I access the page from the menu, I see the contents of the page, but they are on top of the dadabik "frame" - so not really customised as required.

If I add the page as as external link, it shows as a blank page (like the script has "died", even though I'm logged in)

If I add it as in internal link, I get a 404 page not found. (I've tried putting the page in the same folder as index.php - and I also have an html custom page in there, which works fine as an external link)

$enable_custom_php_pages = 1; is set in my custom config.

I've tried to get it working with the only thing on the page this simple code:

<?php

global $conn;

if(!defined('custom_page_from_inclusion')) { die(); }

// Display the page content for logged-in users
echo "Welcome to the secure page!";
?>


but no luck.
Thanks in advance.
 

deep64blue

DaDaBIK Guru
I see the contents of the page, but they are on top of the dadabik "frame" - so not really customised as required.
Could you share a screenshot please?

Does the page work if you run it outside dadabik?

This is how a custom page should look in the pages tab:-

1708634335437.png
 

karen

Member
Hi, this is how it looks when I do it as a custom php page:
1708677905031.png
however, the page renders like this:

1708677959269.png
so the text is within the DDB framework, and I want it to be a totally separate page, with a custom design.

The page works as an external link, but only if I remove

if(!defined('custom_page_from_inclusion')) { die(); }

although, I want the page to only be visible to logged in users, I'm not sure which code line I need to add to make the page only visible when users are logged in?
Thanks.
 

deep64blue

DaDaBIK Guru
so the text is within the DDB framework
OK that is working properly then.
I want it to be a totally separate page, with a custom design.
OK then you can't use dadabik variables to check for being logged on.

Here is a crude check script:-
PHP:
<?php
$cookie_name = "dtest2024a";  //$dadabik_session_name from config_custom.php
if(!isset($_COOKIE[$cookie_name])) {
  echo "<p>Sorry you are not logged on!</p>";
} else {
    echo "<p>Welcome logged on user!</p>";
}
?>
 

karen

Member
Hi thanks a lot for that - I put your script on the top of my page and replaced the session name .. but even when logged out and using a chrome incognito tab if I go to xxxxxxx/testpage.php I still get to see the Welcome logged on user message, even when not logged in?

So I've messed about and used this code:

<?php
session_start();

if(isset($_SESSION['logged_user_infos_ar']["id_user"])) {
echo "<p>Welcome logged on user!</p>";
} else {
echo "<p>Sorry, you are not logged on!</p>";
}
?>


and now it does the opposite, tells me I'm not logged in even when I am 😭
 
Last edited:

deep64blue

DaDaBIK Guru
Oops the session must still be set.

Your code won't work as you're trying to read Dadabik values from outside Dadabik.

Can you explain your use case - what exactly are you trying to achieve and why don't you just present the information inside Dadabik which is straightforward.
 

karen

Member
ok, so I need complete customisation of the shell of the application, also I need custom dropdown menus etc, and a custom dashboard,
The easiest way I thought of doing this was create a custom website and then using "embed" from dadabik to put the tables where I want them on the website.
I don't want to directly edit the DDB shell as this will be overwritten with upgrade.
I thought if I made the pages all in the same folder as the dadabik application, then I would be able to use the same values. Maybe not then!

The other option I guess I could use something you mentioned in another post, to create a custom login page? and then use page protection via my custom pages?

Is the only way to do this by using the Platinum API? I'm guessing we will upgrade to that at some point, but I'm just experimenting with what the company requires the app to look like at the minute.
 
Last edited:

eugenio

Administrator
Staff member
Hello,
only checking the cookie is not secure. Maybe you could just use the "show embed code" button on the grid to grab the code you then use in your own custom page? If you are not logged in, your custom page will be displayed anyway but the actual datagrid won't.

Best,
 

prettem

Member
hello Karen,
Did you find a solution to display the page without the DaDaBIK menu and so on? I'm also looking for a way to display a custom page via an iframe, but only for logged-in users. Still trying unsuccessfully though.
 

karen

Member
Hi prettem, not yet, but I can see how it would work as Eugenio suggests above, the custom page could be made with the iframe, and would be available without authentication, ie, mywebsite/custompage.html - but the iframe inside the page would not display the information unless the user was logged in. If this is not what you are after, then my latest thread, which I'm trying to resolve would cover this.
I need to make an app from an already existing database, and all the pages will be totally custom with iframes.. if I can get it to work...
 

karen

Member
Update - I have a kind of solution I think, it seems to be working, but I'd like a second opinion on the security of it.
The idea is to be able to display embedded Dadabik information on custom pages (not part of the Dadabik app itself), which are only for logged in users, without the user having to login to my website and then login to Dadabik to see the iframe.
I have created an after login hook as per below:

$hooks['login']['after'] = 'dadabik_generateToken';

// Function to generate and set random token cookie

function dadabik_generateToken($id_user) {
$token = uniqid(); // Generate a unique token
$expiration = time() + 3600; // Set expiration time (e.g., 1 hour)

// Set the token as a secure HTTP only cookie
setcookie('token', $token, $expiration, '/', '', true, true);
}

And then, at the head of my custom webpage, I have inserted the following code (which will be needed at the head of every page of the website if you do not want any publicly available):

<?php
// Check if the user is logged in based on the presence of the token
if(isset($_COOKIE['token'])) {
// User is logged in, allow access to the webpage
// Add your webpage content here
} else {
// User is not logged in, redirect to the login page
header('Location: login.php');
exit();
}
?>

I think this might be what you are after @prettem ?
 

karen

Member
Update: although the above works well, I have realised that when embedding a table view, I lose the edit/view/delete functionalilty.
Is there a workaround for this? I'm basically trying to achieve a custom "outer" template without editing dadabik files (due to issues when upgrading in future)
I need all of dadabik within the red square, and then my custom header and side menu, with my extra custom pages and links within my other app.
Dadabik works so perfectly for everything else I need to do.


dbik.JPG
 

deep64blue

DaDaBIK Guru
I need all of dadabik within the red square
Do you really mean this (because you could just do an iframe with the dadabik url if that's what you mean) or do you mean you want the dadabik content (the bit you've outlined in red)?

I feel like you are making things really difficult for yourself, with all the options Dadabik offers (custom css, custom pages, operational hooks, embedded reporting, etc) that you would be better giving it a go to try and achieve everything within Dadabik itself.
 

karen

Member
Hi thanks for the reply. The iframes option doesn't work for the tables, the view, edit and delete buttons are not there? So in that regard, I mean the content.
The reports and views would be fine to do this way, which was my original intention, to embed.

Regarding custom css etc, I don't think this can work.. I need the menu on the left to be customised - I need links to other parts of my custom website, pages which are not part of Dadabik. I understand I can add them via Dadabik via custom pages but I need the menu to look a bit like the example below:
1710701845332.png

If it's easier to "re do" the whole left side menu, then yes, I will do that, but the oher issue it seems is that tables in Dadabik go into the menu and cannot be hidden? There are some tables, which are functional only, which do not need to be in the menu. Is there a way to remove them?
Thanks.
 

deep64blue

DaDaBIK Guru
I need links to other parts of my custom website, pages which are not part of Dadabik. I understand I can add them via Dadabik via custom pages but I need the menu to look a bit like the example below:
I would argue Dadabik looks a bit like your picture (and there's a new UI coming) :cool: but obviously only you know the details of your use case and what is driving this requirement.

tables in Dadabik go into the menu and cannot be hidden? There are some tables, which are functional only, which do not need to be in the menu. Is there a way to remove them?
Tables can be in the database and not in Dadabik or in Dadabik but users not have permission to see them.
 

karen

Member
Hi thanks... do you know when the new UI coming.. have I missed something?? :sneaky:
And re the showing tables with the CRUD functions, is this possible, or I have to code a table myself?
Thanks :)
 
Top