php if statement based on previous click through url in WordPress

I’m trying to write an if statement based on the url of the previously click page_id

Something like this:

Read More
<?php 
$page_id = " the id or url of the page clicked to get to this page"
if($page_id){
    jr_register_form_jseeker( $redirect, $role ); 
}else{
    jr_register_form( $redirect, $role ); 
}
?>

I’ve looked at is_page() but that only seems to deal with the current page…?

Any ideas..?

Thanks

Related posts

Leave a Reply

2 comments

  1. There is no wordpress function that returns the id of the previous page. However, you can use $_SERVER['HTTP_REFERER']. It should contain the ID of the previous page as a parameter. In combination with parse_url and parse_str you should be able to get the ID:

    parse_str(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY), $output);
    $id = $output['p'];
    

    (Not tested)