Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/352879859132928000
added 3 characters in body
Source Link
bysanchy
  • 110
  • 1
  • 12

Thank you for reading! There's a lot redirecting going on on the site I'm creating.

For example,

  • if not logged in user access a "private" page, he will be redirected to a custom login page.

  • if the user logs in, he will be redirected to the last page he visited before accessing the login form.

Let's call the pages "Profile" and "LogIn".

So, if everything goes well should be:

-> not logged try to access Profile -> redirect to LogIn -> if OK redirect to Profile

However, when LogIn calls wp_get_referer(), it does NOT return Profile. Instead it goes "2 pages" back.

Is like "wp_get_referer()" is not seing Profile as the referer because is acting as a redirection. Just like the "Back" button in the browser would.

If you go to the LogIn through any other'public' page (clicking the link) the redirect after login in works fine.

page-profile.php

if( !is_user_logged_in() ) {    
    wp_redirect( get_permalink(37) ); //id 37 = page-login.php
    exit;
}

page-login.php

//Set referer
$referer = wp_get_referer();
if( !$referer || referer_is_login_page($referer) )
    $referer = get_bloginfo('url');
simpleSessionSet('login_referer', $referer);

... 
//Log the user in 
...

if ( is_wp_error($user_id) )            
    $errores = TRUE;
else 
    wp_redirect( simpleSessionGet('login_referer', '') );

Thank you for reading! There's a lot redirecting going on on the site I'm creating.

For example,

  • if not logged in user access a "private" page, he will be redirected to a custom login page.

  • if the user logs in, he will be redirected to the last page he visited before accessing the login form.

Let's call the pages "Profile" and "LogIn".

So, if everything goes well should be:

-> not logged try to access Profile -> redirect to LogIn -> if OK redirect to Profile

However, when LogIn calls wp_get_referer(), it does NOT return Profile. Instead it goes "2 pages" back.

Is like "wp_get_referer()" is not seing Profile as the referer because is acting as a redirection. Just like the "Back" button in the browser would.

If you go to the LogIn through any other page (clicking the link) the redirect after login in works fine.

page-profile.php

if( !is_user_logged_in() ) {    
    wp_redirect( get_permalink(37) ); //id 37 = page-login.php
    exit;
}

page-login.php

//Set referer
$referer = wp_get_referer();
if( !$referer || referer_is_login_page($referer) )
    $referer = get_bloginfo('url');
simpleSessionSet('login_referer', $referer);

... 
//Log the user in 
...

if ( is_wp_error($user_id) )            
    $errores = TRUE;
else 
    wp_redirect( simpleSessionGet('login_referer', '') );

Thank you for reading! There's a lot redirecting going on on the site I'm creating.

For example,

  • if not logged in user access a "private" page, he will be redirected to a custom login page.

  • if the user logs in, he will be redirected to the last page he visited before accessing the login form.

Let's call the pages "Profile" and "LogIn".

So, if everything goes well should be:

-> not logged try to access Profile -> redirect to LogIn -> if OK redirect to Profile

However, when LogIn calls wp_get_referer(), it does NOT return Profile. Instead it goes "2 pages" back.

Is like "wp_get_referer()" is not seing Profile as the referer because is acting as a redirection. Just like the "Back" button in the browser would.

If you go to the LogIn through any 'public' page (clicking the link) the redirect after login in works fine.

page-profile.php

if( !is_user_logged_in() ) {    
    wp_redirect( get_permalink(37) ); //id 37 = page-login.php
    exit;
}

page-login.php

//Set referer
$referer = wp_get_referer();
if( !$referer || referer_is_login_page($referer) )
    $referer = get_bloginfo('url');
simpleSessionSet('login_referer', $referer);

... 
//Log the user in 
...

if ( is_wp_error($user_id) )            
    $errores = TRUE;
else 
    wp_redirect( simpleSessionGet('login_referer', '') );
added 34 characters in body
Source Link
bysanchy
  • 110
  • 1
  • 12

Thank you for reading! There's a lot redirecting going on on the site I'm creating.

For example,

  • if not logged in user access a "private" page, he will be redirected to a custom login page.

  • if the user logs in, he will be redirected to the last page he visited before accessing the login form.

Let's call the pages "Profile" and "LogIn".

So, if everything goes well should be:

-> not logged try to access Profile -> redirect to LogIn -> if OK redirect to Profile

However, when LogIn calls wp_get_referer(), it does NOT return Profile. Instead it goes "2 pages" back.

Is like "wp_get_referer()" is not seing Profile as the referer because is acting as a redirection. Just like the "Back" button in the browser would.

If you go to the LogIn through any other page (clicking the link) the redirect after login in works fine.

page-profile.php

if( !is_user_logged_in() ) {    
    wp_redirect( get_permalink(37) ); //id 37 = page-login.php
    exit;
}

page-login.php

//Set referer
$referer = wp_get_referer();
if( !$referer || referer_is_login_page($referer) )
    $referer = get_bloginfo('url');
simpleSessionSet('login_referer', $referer);

... 
//Log the user in 
...

if ( is_wp_error($user_id) )            
    $errores = TRUE;
else 
    wp_redirect( simpleSessionGet('login_referer', '') );

Thank you for reading! There's a lot redirecting going on on the site I'm creating.

For example,

  • if not logged in user access a "private" page, he will be redirected to a custom login page.

  • if the user logs in, he will be redirected to the last page he visited before accessing the login form.

Let's call the pages "Profile" and "LogIn".

So, if everything goes well should be:

-> not logged try to access Profile -> redirect to LogIn -> if OK redirect to Profile

However, when LogIn calls wp_get_referer(), it does NOT return Profile. Instead it goes "2 pages" back.

Is like "wp_get_referer()" is not seing Profile as the referer because is acting as a redirection. Just like the "Back" button in the browser would.

If you go to the LogIn through any other page (clicking the link) the redirect after login in works fine.

page-profile.php

if( !is_user_logged_in() ) {    
    wp_redirect( get_permalink(37) ); //id 37 = page-login.php
    exit;
}

page-login.php

//Set referer
$referer = wp_get_referer();
if( !$referer || referer_is_login_page($referer) )
    $referer = get_bloginfo('url');
simpleSessionSet('login_referer', $referer);

...

if ( is_wp_error($user_id) )            
    $errores = TRUE;
else 
    wp_redirect( simpleSessionGet('login_referer', '') );

Thank you for reading! There's a lot redirecting going on on the site I'm creating.

For example,

  • if not logged in user access a "private" page, he will be redirected to a custom login page.

  • if the user logs in, he will be redirected to the last page he visited before accessing the login form.

Let's call the pages "Profile" and "LogIn".

So, if everything goes well should be:

-> not logged try to access Profile -> redirect to LogIn -> if OK redirect to Profile

However, when LogIn calls wp_get_referer(), it does NOT return Profile. Instead it goes "2 pages" back.

Is like "wp_get_referer()" is not seing Profile as the referer because is acting as a redirection. Just like the "Back" button in the browser would.

If you go to the LogIn through any other page (clicking the link) the redirect after login in works fine.

page-profile.php

if( !is_user_logged_in() ) {    
    wp_redirect( get_permalink(37) ); //id 37 = page-login.php
    exit;
}

page-login.php

//Set referer
$referer = wp_get_referer();
if( !$referer || referer_is_login_page($referer) )
    $referer = get_bloginfo('url');
simpleSessionSet('login_referer', $referer);

... 
//Log the user in 
...

if ( is_wp_error($user_id) )            
    $errores = TRUE;
else 
    wp_redirect( simpleSessionGet('login_referer', '') );
improved the code
Source Link
bysanchy
  • 110
  • 1
  • 12

Thank you for reading! There's a lot redirecting going on on the site I'm creating.

For example,

  • if not logged in user access a "private" page, he will be redirected to a custom login page.

  • if the user logs in, he will be redirected to the last page he visited before accessing the login form.

Let's call the pages "Profile" and "LogIn".

So, if everything goes well should be:

-> not logged try to access Profile -> redirect to LogIn -> if OK redirect to Profile

However, when LogIn calls wp_get_referer(), it does NOT return Profile. Instead it goes "2 pages" back.

Is like "wp_get_referer()" is not seing Profile as the referer because is acting as a redirection. Just like the "Back" button in the browser would.

If you go to the LogIn through any other page (clicking the link) the redirect after login in works fine.

page-profile.php

if( !is_user_logged_in() ) {    
    wp_redirect( get_permalink(37) ); //id 37 = page-login.php
    exit;
}

page-login.php

// Set referer
$referer = wp_get_referer();
if( !$referer || referer_is_login_page($referer) {)
    simpleSessionSet('login_referer',$referer = get_bloginfo('url'));
} elseif( !referer_is_login($referer) ) {   
    simpleSessionSet('login_referer', $referer);
}

...

if ( is_wp_error($user_id) )            
    $errores = TRUE;
else {
    wp_redirect( simpleSessionGet('login_referer', '') );

}

Thank you for reading! There's a lot redirecting going on on the site I'm creating.

For example,

  • if not logged in user access a "private" page, he will be redirected to a custom login page.

  • if the user logs in, he will be redirected to the last page he visited before accessing the login form.

Let's call the pages "Profile" and "LogIn".

So, if everything goes well should be:

-> not logged try to access Profile -> redirect to LogIn -> if OK redirect to Profile

However, when LogIn calls wp_get_referer(), it does NOT return Profile. Instead it goes "2 pages" back.

Is like "wp_get_referer()" is not seing Profile as the referer because is acting as a redirection. Just like the "Back" button in the browser would.

If you go to the LogIn through any other page (clicking the link) the redirect after login in works fine.

page-profile.php

if( !is_user_logged_in() ) {    
    wp_redirect( get_permalink(37) ); //id 37 = page-login.php
    exit;
}

page-login.php

// Set referer
$referer = wp_get_referer();
if( !$referer ) {
    simpleSessionSet('login_referer', get_bloginfo('url'));
} elseif( !referer_is_login($referer) ) {   
    simpleSessionSet('login_referer', $referer);
}

...

if ( is_wp_error($user_id) )            
    $errores = TRUE;
else {
    wp_redirect( simpleSessionGet('login_referer', '') );

}

Thank you for reading! There's a lot redirecting going on on the site I'm creating.

For example,

  • if not logged in user access a "private" page, he will be redirected to a custom login page.

  • if the user logs in, he will be redirected to the last page he visited before accessing the login form.

Let's call the pages "Profile" and "LogIn".

So, if everything goes well should be:

-> not logged try to access Profile -> redirect to LogIn -> if OK redirect to Profile

However, when LogIn calls wp_get_referer(), it does NOT return Profile. Instead it goes "2 pages" back.

Is like "wp_get_referer()" is not seing Profile as the referer because is acting as a redirection. Just like the "Back" button in the browser would.

If you go to the LogIn through any other page (clicking the link) the redirect after login in works fine.

page-profile.php

if( !is_user_logged_in() ) {    
    wp_redirect( get_permalink(37) ); //id 37 = page-login.php
    exit;
}

page-login.php

//Set referer
$referer = wp_get_referer();
if( !$referer || referer_is_login_page($referer) )
    $referer = get_bloginfo('url');
simpleSessionSet('login_referer', $referer);

...

if ( is_wp_error($user_id) )            
    $errores = TRUE;
else 
    wp_redirect( simpleSessionGet('login_referer', '') );
added 15 characters in body
Source Link
bysanchy
  • 110
  • 1
  • 12
Loading
added code on request
Source Link
bysanchy
  • 110
  • 1
  • 12
Loading
added code on request
Source Link
bysanchy
  • 110
  • 1
  • 12
Loading
Source Link
bysanchy
  • 110
  • 1
  • 12
Loading