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

sam0081's avatar

How to check request is from same domain in laravel

How to check request is from same domain in laravel . if request is from same website domain then user enter in website..

otherwise user would not enter website or not able to hit the multiple request and database .

this i am doing for security

thanks

0 likes
5 replies
sam78640's avatar

You can use HTTP Headers and use HTTP_REFERER header to verify that.

In your controller you can use this code to fetch the referer header

request()->headers->get('referer')

and this will return you the url where the user came from.

sam78640's avatar

@sam0081: Well you need to use some kind of regex or string manipulation to get that using explode and then getting the hostname.

1 like
hlgrrnhrdt's avatar

Use PHP function parse_url() to get the host.

$host = parse_url(request()->headers->get('referer'), PHP_URL_HOST);
2 likes

Please or to participate in this conversation.