close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

See username after login on landing page, restrict access to the page and logout

Thread began 9/19/2018 3:03 am by María Luisa | Last modified 9/27/2018 12:11 am by Ray Borduin | 2687 views | 24 replies |

María Luisa

See username after login on landing page, restrict access to the page and logout

Hello, thanks for reading.
I have the following WA code on the destination page after login:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php require_once('../Connections/Prueba_MCC_i.php'); ?>
<?php require_once('../webassist/mysqli/rsobj.php'); ?>
<?php require_once('../webassist/mysqli/authentication.php'); ?>
<?php require_once('../webassist/mysqli/queryobj.php'); ?>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$RestrictAccess = new WA_MySQLi_Auth();
$RestrictAccess->Action = "restrict";
$RestrictAccess->Name = "user";
$RestricAccessRedirect = "MCC_error.php";
if (function_exists("rel2abs")) $RestricAccessRedirect = $RestricAccessRedirect?rel2abs($RestricAccessRedirect,dirname(__FILE__)):"";
$RestrictAccess->FailRedirect = $RestricAccessRedirect;
$RestrictAccess->execute();
}
?>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$LogOut = new WA_MySQLi_Auth();
$LogOut->Action = "logout";
$LogOut->Name = "user";
$LogOut->execute();
}
?>

In my Connections panel, the Session that has two elements appears. One of them is the name of the user (which I call "u_nombre_completo") I have dragged to the place of my document where I want it to be seen. This is the resulting code:

<div class="Llamada">
Estás autenticada/o como: <?php echo $_SESSION['u_nombre_completo']; ?><span class="Separador"> </span> | <a href="#" class="Enlace_1">Cerrar sesión</a> </div>

However, three things happen:

1. The page is not really restricted to access even though I included the WA behavior restricting access.
2. The username placed the way I did it, gives the following php error

Notice: Undefined index: u_nombre_completo in /Applications/MAMP/htdocs/MCC_01_edicion_DW/__admin/edicion.php on line 150
| Cerrar sesión

which corresponds precisely to the variable:

<?php echo $_SESSION['u_nombre_completo']; ?>

3. I can not find in MySQLi Server Behaviors the way to put the corresponding link in the button logout ("Cerrar Session")

I think I've looked at the tutorials, but I can not find the solutions to my problems.

Can anybody help me please. Thank you very much

Sign in to reply to this post

Ray BorduinWebAssist

1) You will need to update the "restrict access" server behavior and change the trigger from "form submit" to "before page load". Right now it wouldn't restrict access to the page unless they submit a form on it.

2) This might be because the user hasn't logged in yet. I'd have to see the code on the login page to be sure that the session variable is stored properly there.

3) This is by changing the logout server behavior trigger. You can use the "button pressed" trigger to logout only after a button is pressed.

Sign in to reply to this post
Did this help? Tips are appreciated...

María Luisa

Answer to question 3 (LogOut)

Hello and thank you very much, Ray, for the response.

In the MySQLi SB - LogOut panel, I do not see the "button pressed" trigger. Attached a screenshot.

On the other hand, I want the link called "Cerrar sesión" in Spanish to be useful so that when you click it, the user closes it. At this time in the <a href> tag I have open the <? Php?> Tag but I do not know what to put there. With the old Server Behaviors panel, I just dragged from the Bindings <? Php echo $ _SESSION ['MM_Username']?> Panel and up there.

This is my code
<div class="Llamada">
Estás autenticada como: <?php echo $_SESSION['u_nombre_completo']; ?><span class="Separador"> </span> | <a href="<?php ?>" class="Enlace_1">Cerrar sesión</a> </div>
</div>

How should I do, please?

Sign in to reply to this post

María Luisa

On question 2)

Hello again and thanks.

This is my code on the page where the login form is:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php require_once('../Connections/Prueba_MCC_i.php'); ?>
<?php require_once('../webassist/mysqli/rsobj.php'); ?>
<?php require_once('../webassist/mysqli/authentication.php'); ?>
<?php
$Recordset1 = new WA_MySQLi_RS("Recordset1",$Prueba_MCC_i,1);
$Recordset1->setQuery("SELECT usuarios.u_email, usuarios.u_password, usuarios.u_nombre_completo FROM usuarios");
$Recordset1->execute();?>
<?php
$Authenticate = new WA_MySQLi_Auth($Prueba_MCC_i);
$Authenticate->Action = "authenticate";
$Authenticate->Trigger = ($_SERVER["REQUEST_METHOD"] == "POST");
$Authenticate->Name = "MCC_usuario";
$Authenticate->Table = "usuarios";
$Authenticate->addFilter("u_email", "=", "s", "".($Recordset1->getColumnVal("u_email")) ."");
$Authenticate->addFilter("u_password", "=", "s", "".($Recordset1->getColumnVal("u_password")) ."");
$Authenticate->storeResult("u_nombre_completo", "u_nombre_completo");
$Authenticate->storeResult("u_email", "u_email");
$Authenticate->RememberMe = false;
$Authenticate->SaveLogin = false;
$Authenticate->AutoReturn = false;
$SuccessRedirect = "edicion.php";
$FailedRedirect = "MCC_error.php";
if (function_exists("rel2abs")) $SuccessRedirect = $SuccessRedirect?rel2abs($SuccessRedirect,dirname(__FILE__)):"";
if (function_exists("rel2abs")) $FailedRedirect = $FailedRedirect?rel2abs($FailedRedirect,dirname(__FILE__)):"";
$Authenticate->SuccessRedirect = $SuccessRedirect;
$Authenticate->FailRedirect = $FailedRedirect;
$Authenticate->execute();
?>

I would say that it saves session variables. Specifically:

$Authenticate->storeResult("u_nombre_completo", "u_nombre_completo");
$Authenticate->storeResult("u_email", "u_email");

Although now there is another problem: I get the connection errors and neither arrives at the error page nor at the login page. These are the errors that it gives me that have to do with the automatic script generated by MySQLi SB authentication.php

Notice: Undefined property: WA_MySQLi_Auth::$Log in /Applications/MAMP/htdocs/MCC_01_edicion_DW/webassist/mysqli/authentication.php on line 274

Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/MCC_01_edicion_DW/webassist/mysqli/authentication.php:274) in /Applications/MAMP/htdocs/MCC_01_edicion_DW/webassist/mysqli/authentication.php on line 445

--- line 274:
if (sizeof($this->Log) > 0) {

---line 445:
header("location: " . $this->addQuerystring($url));


I do not understand what is happening. Thanks for the help.

Sign in to reply to this post

María Luisa

On question 1)

This is my code generated with the MySQLi SB extension:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php require_once('../Connections/Prueba_MCC_i.php'); ?>
<?php require_once('../webassist/mysqli/rsobj.php'); ?>
<?php require_once('../webassist/mysqli/authentication.php'); ?>
<?php
if ("" == "") {
$RestrictAccess = new WA_MySQLi_Auth();
$RestrictAccess->Action = "restrict";
$RestrictAccess->Name = "MCC_usuario";
$RestricAccessRedirect = "MCC_error.php";
if (function_exists("rel2abs")) $RestricAccessRedirect = $RestricAccessRedirect?rel2abs($RestricAccessRedirect,dirname(__FILE__)):"";
$RestrictAccess->FailRedirect = $RestricAccessRedirect;
$RestrictAccess->execute();
}
?>
<?php require_once('../webassist/mysqli/queryobj.php'); ?>

On question 1)

This is my code generated with the MySQLi SB extension

Does not restrict access

Thanks again for answering. regards :)

Sign in to reply to this post

Ray BorduinWebAssist

It looks like you have a trigger of "before page load" and left the filter tab blank.

You would probably want to use a trigger of a form button press event, and then add filters to find the username and password entered in the form.

Sign in to reply to this post
Did this help? Tips are appreciated...

María Luisa

LogIn does not work :(

Thanks Ray and hello

In the access form I used the Triger "Ani form post" because in the tutorial of use of the extension there is a screenshot where it appears like this.

Assistant screenshot

I have changed it to press the form button and it still does not work and it gives several PHP errors:
___

Notice: Undefined property: WA_MySQLi_Auth::$Log in /Applications/MAMP/htdocs/MCC_01_edicion_DW/webassist/mysqli/authentication.php on line 274

Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/MCC_01_edicion_DW/webassist/mysqli/authentication.php:274) in /Applications/MAMP/htdocs/MCC_01_edicion_DW/webassist/mysqli/authentication.php on line 445
___

When you say:

"You would probably want to use a trigger of a form button press event, and then add filters to find the username and password entered in the form."

Is it in the recordset where I have to introduce a filter? Which? Maybe some WHERE clause. None of that is said in the tutorials

Thanks again

Sign in to reply to this post

Ray BorduinWebAssist

The trigger in the code:

if ("" == "") {

is from "before page load", so the screen shot doesn't match the code you sent previously.

Can I get FTP access to your server and a url to the page to test with? Please attach the .php page you are working on when posting so I can look at the code to see what might be causing issues.

The notice is causing the warning. It looks like the authentication.php file needs to be updated to fix the notice, but for now you can add this line to the top of the page:

<?php
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>

I'll get it corrected in the next build, but that line will make it ignore the notice since it is inconsequential as long as it isn't written to the page.

Sign in to reply to this post
Did this help? Tips are appreciated...

María Luisa

Thanks Ray

I understood that when you talk about choosing the name of the button on the trigger, you mean, like the tutorials I have read with great interest, that it is necessary to include a form with a submit button on which the trigger can be activated.

For me it is being complicated because I am used to working with the old panels Server Behaviors and Bindings of Dreamweaver in which behaviors like Close Session were applied on an <a> element ... I was looking for the same in MySQLi Server Behaviors. But the operation of this extension is quite different from the old obsolete code tools with which I handle so well.

Now I have placed those submit buttons to trigger the action and I still have some doubts because, in reality, I do not get to click on them to close the session nor, redirect the user to the login page...

I also can not even restrict access to the page. There is something there that escapes me. I hope during this weekend to send you a link with the files so you can check them out (something that I appreciate very much like the reading and the answers).

Sign in to reply to this post

Ray BorduinWebAssist

You can use a trigger of <?php echo(isset($_GET["logout"])?"1":""); ?>

That would allow you to logout with <a> tag by just using <a href="page.php?logout">log out</a>

It might be best if you can send me FTP access and a url to reproduce your issues. Then I can take a look at what you have done and test it live and make any necessary updates for you to save some time back and forth.

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...