This time we will customize the PHPMaker 9.0.1 template in order to save the last users’ visitted page. In other words, when your user is visitting the certain page in your web application, system will save that last visitted page which he/she has just visitted into your users table. This is very important, since we can manage this information for various uses. For example, when your user login back in the future, he/she will be redirected back to the last visitted page he/she visitted. The other example: you are able to redirect your user back to the last visitted page after he/she has done some actions in your web application which located in another page than he/she is visitting without having do the logout process.
I have successfully created this redirect to last page feature into websites that generated by PHPMaker 9.0.1. Now you are also able to define whether you want to enable or disable this feature by simple adjusting the related constant in your configuration (ewcfg9.php) file. Here is the conditions how you should enable or disable this feature. You should enable this redirect back to the last visitted page feature when you give the flexibility to your users to go back to their last visitted page. In the other side, you should disable this redirect to last visitted page feature when you want to force all of your users by redirecting them to the certain very important page other than their own last visitted page.
For that both cases, the constant value in the configuration file will overide the related setting in their user setting preferences. Now the control is in your hand. In the next article, I will show you how you can use this users’ last visitted page for another important purpose.
Updated on May 30, 2012: This customization has been implemented in PHPMaker version 9.0.2, it matches to each other, and as a result, it works properly.
Updated on July 22, 2012: This customization has been implemented in PHPMaker version 9.0.3, it matches to each other, and as a result, it works properly.
Updated on September 5, 2012: This customization has been implemented in PHPMaker version 9.0.4, it matches to each other, and as a result, it works properly.
Updated on November 28, 2012: This customization has been implemented in PHPMaker version 9.1.0, it matches to each other, and as a result, it works properly.
Updated on February 9, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.
Updated on June 17, 2013: The customization has been handled by using MasinoFixedWidthSite extension. You don’t need to implement the customization below if you use my extensions together with the original PHPMaker Template and Extension files.
[hidepost]
-
First of all, we have to alter the users table by adding two new fields:
- current_url (text)
- redirect_to_last_visitted_page_after_login (type=enum; values=’Y', ‘N’; default=’Y') -
Open your \Script\ewcfg.php file, and find this code:
// General
before that line, please insert the following code:
// Begin of modification Redirect to Last URL Page after login, by Masino Sinaga, May 25, 2012 define("MS_REDIRECT_TO_LAST_VISITTED_PAGE_AFTER_LOGIN", TRUE, TRUE); // defaul: redirect to last visitted page // End of modification Redirect to Last URL Page after login, by Masino Sinaga, May 25, 2012 -
Still in that \Script\ewcfg.php file, find again this code:
define("EW_USER_TABLE", "<!--##=ew_Quote(sUserTable)##-->", TRUE);after that line, please insert the following code:
// Begin of modification Save Last Users' Visitted Page, by Masino Sinaga, May 25, 2012 define("MS_USER_ID_FIELD", "<!--##=ew_Quote(sFld)##-->", TRUE); <!--## // Set security table current if (ew_IsNotEmpty(PROJ.SecPasswdFld)) { FIELD = SECTABLE.Fields(PROJ.SecPasswdFld); sPasswordFldName = FIELD.FldName; } ##--> define("MS_USER_PASSWORD_FIELD", "<!--##=ew_Quote(sPasswordFldName)##-->", TRUE); // End of modification Save Last Users' Visitted Page, by Masino Sinaga, May 25, 2012 -
Open your \Script\phpcommon-scripts.php file, and find this code:
<!--##~SYSTEMFUNCTIONS.Security()##-->
after that line, please insert the following code:
// Begin of modification Save Last Users' Visitted Page, by Masino Sinaga, May 25, 2012 <!--## if (PROJ.SecType != "None" && PROJ.SecType != "Hard Code") { ##--> <!--## if (CTRL.CtrlID != "preview") { ##--> $lastpage = ew_CurrentPage(); if ($lastpage!='logout.php' && $lastpage!='index.php') { $lasturl = ew_CurrentUrl(); $conn->Execute("UPDATE ".EW_USER_TABLE." SET current_url = '".$lasturl."' WHERE ".MS_USER_ID_FIELD." = '".CurrentUserName()."'"); } <!--## } ##--> <!--## } ##--> // End of modification Save Last Users' Visitted Page, by Masino Sinaga, May 25, 2012As you can see, we will exclude the preview page from this action in order to avoid displyaing this page in the next users' visitting from the following code above:
<!--## if (CTRL.CtrlID != "preview") { ##--> -
Still in that \Script\phpcommon-scripts.php file, find again this code:
function Page_Init() { global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;then replace it with the following code:
function Page_Init() { global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm, $conn; -
The next step is, we will define the main of this customization. Open your PHPMaker project using PHPMaker application, click one of your tables, go to Code (Server Events/Client Scripts and Custom Template -> Other -> Default Page -> Page_Redirecting, and then add this following code into your Page_Redirecting function (if you have never change this function, then the complete code should be like the following):
function Page_Redirecting(&$url) { // Begin of modification Save Last Users' Visitted Page, by Masino Sinaga, May 25, 2012 global $Security; if (!$Security->IsLoggedIn()) { $url = "login.php"; } else { global $conn; $sSql = "SELECT current_url, redirect_to_last_visitted_page_after_login FROM ".EW_USER_TABLE." WHERE ".MS_USER_ID_FIELD." = '".CurrentUserName()."'"; $rs = $conn->Execute($sSql); if ($rs->fields("current_url")!="") { if (MS_REDIRECT_TO_LAST_VISITTED_PAGE_AFTER_LOGIN) { if ($rs->fields("redirect_to_last_visitted_page_after_login")=="Y") { $webdomain = ew_DomainUrl(); $url = $webdomain . $rs->fields("current_url"); } } } } // End of modification Save Last Users' Visitted Page, by Masino Sinaga, May 25, 2012 } - Finally, re-generate all of your php script files using PHPMaker as always.
[/hidepost]
Masino,
There is a small issue with this.
If a user opens up a preview panel and then logs out PRIOR to closing the preview, the last page visited is the preview page WITHOUT any menu or any other means of returning to the normal script pages.
the user must edit the url in order to return and that creates a problem for many of them
Yes. I just modified the code in step 4.
See this part:
<!--## if (CTRL.CtrlID != "preview") { ##--> .... <!--## } ##-->It means that the code inside that block will not be generated for the preview page. Did you implement this part? Let me know. Thanks.
Masino,
Is there a way to prevent the last visited page from being the Detail page in a Master/Detail relationship?
Do you have a demo website for this?
Yes, I do. but, I would rather not post the URL here.
Please send it to my email. Also, tell me in which page you want to prevent displaying it.