Connect with us

Others

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

Published

on

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.
page1.php:
$_SESSION[ ‘display_page2’ ] = TRUE;
//rest of the content

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

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
if(isset($_COOKIE[‘page1’]))
{
//keep displaying page2.php
}else{
//if it is not redirected from page1.php
header(‘Location: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, Admob self-clicking. visit our contact page to get in touch with us or WhatsApp (+234) 08114313795.

Ikuesan Oluwaseun is the CEO of Ofofonobs and a Full-stack Developer. Ofofonobs.com is a Nigerian digital media and news platform launched in July 2020. Kindly check our contact page to get in touch with me.

Advertisement
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.

Entertainment

Hyundai Veloster N TCR Makes World Debut in Detroit Hyundai Veloster N TCR Makes World Debut in Detroit
Entertainment5 months ago

Hyundai Veloster N TCR Makes World Debut in Detroit

Just before it sets of to conquer the race tracks of the 2019 International Motor Sports Association Michelin Pilot Challenge series,...

Reconditioned 1974 Honda CB750 Looks as If It Came Straight Out of a Museum Reconditioned 1974 Honda CB750 Looks as If It Came Straight Out of a Museum
Entertainment5 months ago

Reconditioned 1974 Honda CB750 Looks as If It Came Straight Out of a Museum

You might find it hard to believe, but this 1974 Honda CB750 was nothing more than a non-running project a few years...

Beautiful Music for Successful Wedding Videos Beautiful Music for Successful Wedding Videos
Entertainment5 months ago

Beautiful Music for Successful Wedding Videos

When it comes to wedding videos, ensuring you have the right music at hand can make all the difference. Any...

Why it’s better to have a child with someone you don’t love – Yvonne Nelson spills Why it’s better to have a child with someone you don’t love – Yvonne Nelson spills
Entertainment6 months ago

Why it’s better to have a child with someone you don’t love – Yvonne Nelson spills

Popular Ghanaian actress, Yvonne Nelson has revealed why it’s better and advisable for people to have children with people they are not...

Wizkid’s Made In Lagos Hits Half A Billion Streams On Apple Music Wizkid’s Made In Lagos Hits Half A Billion Streams On Apple Music
Entertainment6 months ago

Wizkid’s Made In Lagos Hits Half A Billion Streams On Apple Music

Nigerian superstar, Wizkid has recorded another feat with his Made In Lagos Deluxe album version with a milestone of 500M...

Blake Snell Net Worth Blake Snell Net Worth
Entertainment8 months ago

Blake Snell Net Worth

What is Blake Snell’s net worth? Net Worth: $10 Million Age: 28 Born: December 4, 1992 Country of Origin: United...

Beenie Man Net Worth Beenie Man Net Worth
Entertainment8 months ago

Beenie Man Net Worth

What is Beenie Man’s net worth? Net Worth: $4 Million Age: 47 Born: August 22, 1973 Country of Origin: Jamaica...

How to load an already used recharge card How to load an already used recharge card
Entertainment10 months ago

See how to load an already used recharge card (Topsecrets)

Have you ever gotten free Airtime Credit from MTN? If you haven’t, you’re still dulling yourself. This article will teach...

Nigerians on Twitter find humour in Oxlade's leaked s*x tape Nigerians on Twitter find humour in Oxlade's leaked s*x tape
Entertainment10 months ago

Nigerians on Twitter find humour in Oxlade’s leaked s*x tape

Full video of a fast-rising singer identified as Oxlade smashing an unidentified lady breaks the internet, Brand Spur Nigeria reports. In the tape...

Oxlade S*x Tape With Unidentified Lady Breaks Internet Oxlade S*x Tape With Unidentified Lady Breaks Internet
Breaking News10 months ago

Oxlade S*x Tape With Unidentified Lady Breaks Internet

Full video of a fast-rising singer identified as Oxlade smashing an unidentified lady breaks the internet, Brand Spur Nigeria reports. The 24-year-old whose...

ADVERTISEMENT