Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Calvin03's avatar

How to get the first page where users go on my website and save it to session

Hi i want to get what is the first page of user that go on my website and save it to my session i use spatie referer to know what is the original page where they click the link going to my website i want to know what is the first page of my website that they went.. thanks! :)

0 likes
3 replies
srinathdudi's avatar

You can create a middleware and attach it to all the routes. Inside the middleware you can determine which page the user is on based on route and store it in the session.

fylzero's avatar
fylzero
Best Answer
Level 67

@calvin03 I don't know why you'd want to save it to your session. Do you mean to the database or something?

It sounds like the use case is, a user visits your website and you want to know the first link they click, right?

It would be easier to just use analytics or like @srinathdudi suggested log all page clicks to a database or log file... because detecting first click is likely going to require you to rig together events on each page and detect the click count based on a cookie or something, then destroy the cookie.

1 like
Calvin03's avatar

hi guys thanks for your replies i already solve the problem i just want to save it to database whenever an user orders a product on my website so that i want to save it as session the first page of the user that went. it's for marketing something thanks :)..

Please or to participate in this conversation.