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

Chris,

One other thing. I am having the same type of issue on my user-profile page as I did with my logoff off since I want to use a custom url instead of what is defined in the membership file. Can I do the same type of thing here? This is in a form so I wasn't sure?

<form action="?" method="post">
<input type="hidden" name="updateAccount" value="1">
<input type="hidden" name="tab" value="5">

<div id="divider">
<h3 class="diagonal-header"><span>Personal Details</span></h3> </div>

<div class="form-label">Full Name:&nbsp;*</div>
<div class="form-field"> <input name="fullname" style="width: 200px;" type="text" value="<?php echo @$CURRENT_USER['fullname']; ?>" /></div>

<div class="form-label">Business Name:&nbsp;*</div>
<div class="form-field"> <input name="business_name" style="width: 290px;" type="text" value="<?php echo @$CURRENT_USER['business_name']; ?>" /></div>


<div class="form-label">Phone:&nbsp;*</div>
<div class="form-field"> <input name="phone" style="width: 290px;" type="text" value="<?php echo @$CURRENT_USER['phone']; ?>" /></div>


<div class="form-label">Zip:&nbsp;*</div>
<div class="form-field"> <input name="zip" style="width: 290px;" type="text" value="<?php echo @$CURRENT_USER['zip']; ?>" /></div>

<div id="divider">
<h3 class="diagonal-header"><span>Account Details</span></h3></div>


<div class="form-label">Email:&nbsp;*</div>
<div class="form-field"> <input name="email" style="width: 290px;" type="text" value="<?php echo @$CURRENT_USER['email']; ?>" /></div>


<div class="form-label">Username:</div>
<div class="form-field"> <input type="text" name="username" value="<?php echo htmlspecialchars(@$CURRENT_USER['username']); ?>" size="50" /></div>

<div class="form-label">Current Password:</div>
<div class="form-field"> <input type="password" name="oldPassword" value="<?php echo htmlspecialchars(@$_REQUEST['oldPassword']); ?>" size="50" /></div>

<div class="form-label">New Password:</div>
<div class="form-field"> <input type="password" name="newPassword1" value="<?php echo htmlspecialchars(@$_REQUEST['newPassword1']); ?>" size="50" /></div>

<div class="form-label">New Password (again):</div>
<div class="form-field"> <input type="password" name="newPassword2" value="<?php echo htmlspecialchars(@$_REQUEST['newPassword2']); ?>" size="50" /></div>

<div class="form-field-full"><input name="submit" type="submit" value="Update" /></div>
</form>

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