# Get last visited page

**URL:** <https://forum.getkirby.com/t/get-last-visited-page/14664>\
**Category:** Questions\
**Tags:** v3\
**Created:** [June 21, 2019, 1:52pm UTC](https://forum.getkirby.com/t/get-last-visited-page/14664 "2019-06-21T13:52:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tideg](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tideg](https://forum.getkirby.com/u/tideg)\
**Post date:** [June 21, 2019, 1:52pm UTC](https://forum.getkirby.com/t/get-last-visited-page/14664/1 "2019-06-21T13:52:45Z")

</div>

Is there a way to query what was the previously visited page? In other words: from which side I came to the current page?

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 21, 2019, 2:53pm UTC](https://forum.getkirby.com/t/get-last-visited-page/14664/2 "2019-06-21T14:53:27Z")

</div>

Do you mean to move to the next or previous sibling? You don’t say which version you are using, so i will assume 3. Please tag your topic with the version number.

> **[$page-\>next()](https://getkirby.com/docs/reference/objects/page/next)**
>
> Returns the next item in the collection if available

> **[$page-\>prev()](https://getkirby.com/docs/reference/objects/page/prev)**
>
> Returns the previous item in the collection if available

If you mean refererer data, then thats easier said than done. You would need to do that from the front end I think.

---

<div class="post-metadata">

**Author:** ![tideg](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tideg](https://forum.getkirby.com/u/tideg)\
**Post date:** [June 21, 2019, 3:34pm UTC](https://forum.getkirby.com/t/get-last-visited-page/14664/3 "2019-06-21T15:34:47Z")

</div>

Thanks for your suggestion @jimbobrjames. In fact, I mean the latter. So there is no way to get the last visited page without using referrer data in the front end?

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [June 21, 2019, 3:42pm UTC](https://forum.getkirby.com/t/get-last-visited-page/14664/4 "2019-06-21T15:42:12Z")

</div>

> [@tideg](#):
>
> So there is no way to get the last visited page without using referrer data in the front end?

Not really, because that happens in the browser, not on the server.

You can set a cookie with javascript and read it back with PHP, then do your thing with the value.

See here. [Setting and reading cookies with JavaScript](https://clubmate.fi/setting-and-reading-cookies-with-javascript/)

You can set the cookies value with `document.refererer`. [See here](https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer). keep in mind it will be empty if they came to the page directly, so you will need to handle that in your php.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 21, 2019, 6:10pm UTC](https://forum.getkirby.com/t/get-last-visited-page/14664/5 "2019-06-21T18:10:03Z")

</div>

What is your use case?

---

<div class="post-metadata">

**Author:** ![tideg](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tideg](https://forum.getkirby.com/u/tideg)\
**Post date:** [June 24, 2019, 7:04am UTC](https://forum.getkirby.com/t/get-last-visited-page/14664/6 "2019-06-24T07:04:42Z")

</div>

I´d like to customize some Back-To Buttons in dependence of the page the user came from. For example:

User comes from Homapage: Back to Homepage  
User comes from Project overview: Back to Project overview

Working with URL-Parameters would work, but maybe there is another option?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 24, 2019, 8:21am UTC](https://forum.getkirby.com/t/get-last-visited-page/14664/7 "2019-06-24T08:21:55Z")

</div>

Browsers already have back buttons. What is your reason to have additional back buttons?

> **["Go Back" Button | CSS-Tricks](https://css-tricks.com/snippets/javascript/go-back-button/)**
>
> Browsers already have "back" buttons, so you'd better have a darn good reason for needing to put one on your page! Input button with inline JavaScript

---

<div class="post-metadata">

**Author:** ![tideg](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tideg](https://forum.getkirby.com/u/tideg)\
**Post date:** [November 13, 2019, 10:53am UTC](https://forum.getkirby.com/t/get-last-visited-page/14664/8 "2019-11-13T10:53:23Z")

</div>

You are totally alright, but the client … In the end I was able to convince them with another solution. Thanks anyway for your solutions!

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [November 13, 2019, 11:52am UTC](https://forum.getkirby.com/t/get-last-visited-page/14664/9 "2019-11-13T11:52:43Z")

</div>

Or use

```php
<a href="javascript:history.back();" title="Back to the last webpage">Back</a>

```

if you need a link.

Needs running javascript in the browser of the visitor.
