I need to pass the current page's URI into either the HTTP headers or as a URL query string so that after being taken to the login page and successfully logging in, the user will be sent back to where they came from.
I think that by attaching a query to any login button around the site I can then tell the login page where to go. The Login button is part of many of my templates / partials show when conditionally displaying content depending on if user is logged in.
By using <a href="members/login?p={% craft.request.path %}">
For example I thought that:
{% if craft.request.getQuery('p') and craft.request.getQuery('p')|length %}
{% set p = craft.request('p') %}
{% else %}
{% set p = '/' %}
{% endif %}
would set me up to redirect if the url contains http://craft.fira/members/login?p=/members/directory/json
. However that results in a 404. Is there a safe way to pass a path into a url query?
Secondly, I then need to know how to deal with this after logging in successfully.
All help greatly appreciated, thank you!