Hi Fred.
This is only applicable to PHP and not NODE…
Security Enforcer - Redirect Only
I use security enforcer on my page, the PHP starts first, as the enforcer sits at the top op the page and will execute first… So even if I user browsergoto referrer it wont work, as the page never got to that code to do its thing. Im not talking about server side with server connect. Im strictly using the enforcer at the top of the page.
This is why I did this…
Sometimes i have a case where i give my client a link like this… this page is “protected” by security enforcer eg… www.test.com/goto/otherpage/page?id=122&code=18383838
When the client then clicks on this form an external link, and when you have security enforcer at the top it will just open and redirect to the physical path you set… as i cannot use referrer or anything as the enforcer execute first. So you will never get redirected from the page you come from.
So here is my “hack” solution
- I get the server link before the enforcer starts. so i know where the link is coming from
- I guess this is the most important part of this hack, I then “replace” all the & and ? with a set template code… otherwise it will not work for obvious reasons.
The i add the the “redirect link” code to the code below
Its basically modifying the original “enforcer” code
<?php
// Set link
$redirect_link = $_SERVER['REQUEST_URI'];
$redirect_link = str_replace('&', '@@S@P@@', $redirect_link);
$redirect_link = str_replace('?', '99x@x99', $redirect_link);
// Require the necessary files
require('dmxConnectLib/dmxConnect.php');
// Construct the JSON string
$json_string = json_encode([
"steps" => [
"Connections/db",
"SecurityProviders/YourSecurity",
[
"module" => "auth",
"action" => "restrict",
"options" => [
// Include the value of $redirect_link properly
"loginUrl" => "login?redirect=" . urlencode($redirect_link),
"forbiddenUrl" => "",
"provider" => "LoginRedirectForm"
]
]
]
]);
// Initialize the App
$app = new \lib\App();
// Execute the JSON data
$app->exec($json_string, TRUE);
?>
So in effect it will go to the login form and take your “redirect link” along in simple terms
Now on your login page, at the op of the page you can add the following php
<?php $redirect = isset ($_GET['redirect']) ? $_GET['redirect'] : '';
$redirect = str_replace('@@S@P@@', '&', $redirect);
$redirect = str_replace('99x@x99', '?', $redirect);
?>
Now we will bring back the & ? where applicable…
So that your link is 100% correct.
So in your form that does the login
<form action="dmxConnect/api/login.php" method="post" name="loginmember" id="loginmember" is="dmx-serverconnect-form" dmx-on:success="browser1.goto(refferervalue.value)">
<dmx-value id="refferervalue" dmx-bind:value="'<?php echo $redirect; ?>'"></dmx-value>
// all your other fields required..... can come here
</form>
So once you submit the login it will know where to go.
This is the only way i could make it work for security enforcer.
One could also use a session i guess
$_SESSION['redirect_link'] = $redirect_link;
and then in the enforcer something link this
"loginUrl" => "login?redirect=" . urlencode($_SESSION['redirect_link']),