Question

how can I dynamically remember last link with php? For instance, this is the parent page's url,

http://website.com/#/events/upcoming-events/ 

note that I have a hash in all URLs.

and this is the child page's,

http://website.com/#/events/upcoming-events/event-1/

On the child page I have a link to go back to the parent page,

<a href="<?php echo $_SERVER['HTTP_REFERER'];?>" class="button-back">Back</a>

$_SERVER['HTTP_REFERER']; only gives me http://website.com/ of course.

How do I get around to this then?

Was it helpful?

Solution

This will be difficult to do on server side but you can do this on client side using jQuery

$(document).ready(function() {
    var hrefParts = location.href.split('/');
    hrefParts.splice(hrefParts.length - 2);
    $('.button-back').attr('href', hrefParts.join('/') + '/');
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top