6

I'm basically trying to create a button that will take the users back to a search results page of a directory. Is there any way to populate href with the url of the previous page?

10

There are a few add-ons that allow you to do this without having to rely on PHP or Javascript.

Mo Variables:

You would want to have <a href="{last_page_visited}">Back to Search Results</a> or you could do <a href="{one_page_visited}">Back to Search Results</a> the nice thing about Mo Variables is that it allows you to grab up to 5 pages of history from the session.

URL Helper:

With URL Helper you would want to use the following <a href="{referrer}">Back to Search Results</a>

They both offer similar functionality with each having something that other does not so evaluate them both and see which one suits your needs the best.

| improve this answer | |
2

If you enable PHP this will output the previous URL. But HTTP_REFERER can be modified by the users browser.

<?=$_SERVER['HTTP_REFERER'];?>

| improve this answer | |
2

I extended a bit on Justin's submission, checking to ensure the reference was from within my own site. Eg. I didn't want to send people back to the Google search results page.

{exp:ce_str:ing allow_eecode="yes|yes" php}
    <?php 
        $referrer = '{referrer}'; // using extension url_helper (http://devot-ee.com/add-ons/url-helper)
        $base_url = '{global:base_url}'; // site base path

        if (strpos($referrer, $base_url) === 0) { // check if they start the same
            echo '<a href="{referrer}">Go back</a>'; // add back link to page within site
        }
    ?>
{/exp:ce_str:ing}
| improve this answer | |
1

you could off course also do a href="javascript:history.back();"

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.