You can use wp_login
hook to get user logged in the first URL. Please put the code in your functions.php
file.
function your_function( $user_login, $user ) {
// your code
if( ! session_id() ) {
session_start();
}
$_SESSION['counter'] = 1;
$_SESSION['visited_url'] = "http://".$_SERVER['HTTP_HOST']."/".$_SERVER['REQUEST_URI'];
}
add_action('wp_login', 'your_function', 10, 2);
if( ! session_id() ) {
session_start();
}
if(is_user_logged_in()){
if(isset($_SESSION['counter']) && $_SESSION['counter'] >=2){
echo $_SESSION['visited_url'];
}else{
$_SESSION['counter'] = $_SESSION['counter']+1;
$_SESSION['visited_url'] = "http://".$_SERVER['HTTP_HOST']."/".$_SERVER['REQUEST_URI'];
}
}
How this code works:
step 1: Once user logged in we set counter
and visited_url
in the session.
step 2: check counter
variable in session and greater equal to 2.
step 3: If it meets the condition we print first visited URL.
It is working code at my side.