Redirect Logoff

By design9 - April 21, 2014

Hello,

Is there any way to redirect the logoff button to a different url that what I have set in the websitemembership.php file? I want to keep the url that I have set in the membership file because I am using that for one section. Then I have a completely different section where I want the post logoff url to be different. 

In case, this makes a difference, I am using this on the page as I want the user to always have to login before seeing content on this page. 

if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }

Thanks!

April

By Chris - April 21, 2014

You can make a custom logoff button by pointing it at a custom script. Instead of <a href="?action=logoff">, set it to <a href="/customLogoff.php">, then create a customLogoff.php file. In it, add this:

<?php

// load viewer library (the usual)
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// log the user off, redirecting them to our custom URL
user_logoff("/custom/redirect/url.php");

?>

Does that help?

All the best,
Chris

By design9 - April 22, 2014

Thanks Chris! That is perfect. 

Can I still use this code so that the user cannot see the content on this page without logging in first since I am not using the url's in the websitemembership.php file? 

   if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }

By design9 - April 22, 2014 - edited: April 22, 2014

In  reference to this question with this code, the issue I have here is that if I were to type the page url directly in browser, it takes me to the login page I have defined in the membership file instead of my custom url login, how do I bypass that?

 if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }

By Chris - April 22, 2014

I think you want to use the redirectBrowserToURL() function.

For example, you can redirect someone to a custom login page if they aren't logged in like this:

if (!$CURRENT_USER) { redirectBrowserToURL("/customLoginUrl.php"); }

To make your form redirect to a custom page after it's completed, you'll need to find where the code completes the action. For example, in Website Membership's sample user-profile.php:

  ### Update User Profile
  if (@$_POST['save']) {

    ...

    $errorsAndAlerts = "Thanks, we've updated your profile!<br/>\n";
  }

You can change that to:

  ### Update User Profile
  if (@$_POST['save']) {

    ...

    redirectBrowserToURL("/thanksForUpdatingYourProfile.php");
  }

Does that answer your question?

All the best,
Chris

By design9 - April 24, 2014

Chris,

I do not have this code in my file.

  ### Update User Profile
  if (@$_POST['save']) {

    ...

    $errorsAndAlerts = "Thanks, we've updated your profile!<br/>\n";
  }

I have attached my page so you can see my code.

Thanks!

April

Attachments:

account.php 17K

By design9 - April 24, 2014

Chris,

You can ignore my last post. I figured it all out! Thanks for all your help! It all works perfectly.

April