Connect with us
Padiwise Banner


How to use $_SERVER[‘HTTP_REFERER’] correctly in php?



How to use $_SERVER[‘HTTP_REFERER’] correctly in php?

I wouldn’t recommend using HTTP_REFERER:

It’s fairly simple to manipulable in browser.
Some users might have security settings in their browser to not send this header at all.
It’s not accessible over HTTPS.
Some proxies strip this header from the request
Added – See answer to this quesion

As Charlotte Dunois stated in the comment, better set session value before sending the form and then check it on page2.
$_SESSION[ ‘display_page2’ ] = TRUE;
//rest of the content

if ( (isset( $_SESSION[ ‘display_page2’ ] ) && $_SESSION[ ‘display_page2’ ] === TRUE ) || isset( $_POST[ ‘some_form_input’ ] ) ) {
//keep displaying page2.php
} else {

With isset( $_POST[ ‘some_form_input’ ] ), you can check whether the form has been sent (via POST method).
When needed, you can unset the session with unset( $_SESSION[ ‘display_page2’ ] ); or by setting it to different value.

I advise against using $_SERVER[‘HTTP_REFERER’] as it can be easily spoofed.
Instead , you could set a cookie when they load page 1 using setcookie(“page1”, 1); before any markup is output. Then check for it on page 2 using
//keep displaying page2.php
//if it is not redirected from page1.php
//redirect the user back to page1.php

By not specifying the expiry date the cookie will expire when the browser is closed. In this situation, using cookies also makes for much more readable code to others.

Disclaimer: We sell any type of script/themes/plugins, we also offer web design/developement, graphics design, SEO, Social media followers, VTU Platform and more. visit our contact page to get in touch with us or WhatsApp (+234) 08114313795.
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Entertainment2 days ago

Diversification 101: How Portfolio Management Can Mitigate Risk

No matter how well-researched and promising a single investment may seem, there is always the chance that something unexpected could...

Entertainment6 days ago

Kristina Goztola Net Worth – How Much is Kristina Goztola Worth?

Kristina Goztola, an accomplished actress and producer, has made a name for herself in the film industry. Born on July...

Entertainment6 days ago

Krista Ayne Net Worth – How Much is Krista Ayne Worth?

Krista Ayne, the renowned model and actress, has captured the hearts of many with her incredible talent and stunning beauty....

Entertainment7 days ago

isaiah Mobley Net Worth – How Much is isaiah Mobley Worth?

Isaiah Mobley, a prominent NBA player, has garnered substantial wealth through his successful basketball career. As of 2024, his estimated...

Entertainment7 days ago

Kim Ross Net Worth – How Much is Kim Ross Worth?

Kimberly A. Ross, the Director of Cigna, is an influential figure in the corporate world with an impressive financial portfolio....

Entertainment7 days ago

Evan Mobley Net Worth – How Much is Evan Mobley Worth?

Welcome to our article on Evan Mobley’s net worth. In this section, we will explore the estimated net worth of...

Entertainment7 days ago

How To Get A Title Loan: All Steps

In a world where financial emergencies or unexpected cash needs can arise, understanding how to secure a title loan could...

Entertainment1 week ago

Kelly McCart Net Worth – How Much is Kelly McCart Worth?

Kelly McCart, a talented actress known for her performances in films such as Locked Up, Final Stop, and To Kill...

Entertainment1 week ago

Kestie Morassi Net Worth – How Much is Kestie Morassi Worth?

Kestie Morassi, an Australian movie actress, has a net worth of $200 thousand as of 2024. Born on August 8,...

Entertainment1 week ago

Davion Mitchell Net Worth – How Much is Davion Mitchell Worth?

According to reliable sources, Davion Mitchell’s net worth is estimated to be $20,951,517. This substantial figure showcases the financial success...