Jump to content

Redirect user to same page after Login


criat

Recommended Posts

To do this redirect I was trying a hook, here's what I came up with:

 

includes/hooks/login-redirect.php

<?php
function onlogin_redirect($vars) {
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("Location: ".$url);
}
add_hook("ClientLogin",1,"onlogin_redirect");
?>

 

Didn't work though, WHMCS goes blank screen.

 

Here's the docs for Hooks: http://docs.whmcs.com/Hooks:Clients

 

Any help would be appreciated!

Link to comment
Share on other sites

It's because of this.

 

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

In other words ClientLogin hook point comes when the page has already sent an output. You have to use an alternative method like this one for example.

 

function onlogin_redirect($vars) 
{

  $url = "http://google.it";

         echo '<script type="text/javascript">';
         echo 'window.location.href="'.$url.'";';
         echo '</script>';
         echo '<noscript>';
         echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
         echo '</noscript>'; exit; 
}
add_hook("ClientLogin",1,"onlogin_redirect");

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated