Connect with us

Others

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

Published

on

How to use $_SERVER[‘HTTP_REFERER’] correctly in php?
Share our content or if you have any questions about an article, leave us a comment.

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.

Entertainment

Blake Snell Net Worth Blake Snell Net Worth
Entertainment2 months ago

Blake Snell Net Worth

Share our content or if you have any questions about an article, leave us a comment. TwitterFacebookGoogle+BufferLinkedInPin ItWhat is Blake...

Beenie Man Net Worth Beenie Man Net Worth
Entertainment2 months ago

Beenie Man Net Worth

Share our content or if you have any questions about an article, leave us a comment. TwitterFacebookGoogle+BufferLinkedInPin ItWhat is Beenie...

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

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

Share our content or if you have any questions about an article, leave us a comment. TwitterFacebookGoogle+BufferLinkedInPin ItHave you ever...

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

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

Share our content or if you have any questions about an article, leave us a comment. TwitterFacebookGoogle+BufferLinkedInPin ItFull video of...

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

Oxlade S*x Tape With Unidentified Lady Breaks Internet

Share our content or if you have any questions about an article, leave us a comment. TwitterFacebookGoogle+BufferLinkedInPin ItFull video of...

Oba Solomon Agbaye Biography, Career, Wife, Net Worth Oba Solomon Agbaye Biography, Career, Wife, Net Worth
Entertainment3 months ago

Oba Solomon Agbaye Biography, Career, Wife, Net Worth

Share our content or if you have any questions about an article, leave us a comment. TwitterFacebookGoogle+BufferLinkedInPin ItAdelana Adekunle Solomon,...

Nigerians react to Obi Cubana’s first son, Alex’s grades in school Nigerians react to Obi Cubana’s first son, Alex’s grades in school
Entertainment4 months ago

Nigerians react to Obi Cubana’s first son, Alex’s grades in school

Share our content or if you have any questions about an article, leave us a comment. TwitterFacebookGoogle+BufferLinkedInPin ItObi Cubana’s first...

Nigerians worry over size of Bobrisky’s head in new video Nigerians worry over size of Bobrisky’s head in new video
Entertainment4 months ago

Nigerians worry over size of Bobrisky’s head in new video

Share our content or if you have any questions about an article, leave us a comment. TwitterFacebookGoogle+BufferLinkedInPin ItControversial crossdresser, Bobrisky has sparked...

Man Arrested For Advertising Fake Eggs On Social Media Man Arrested For Advertising Fake Eggs On Social Media
Entertainment4 months ago

Man Arrested For Advertising Fake Eggs On Social Media

Share our content or if you have any questions about an article, leave us a comment. TwitterFacebookGoogle+BufferLinkedInPin ItA 24-year-old man,...

Scream Director Teases Sam’s Mom’s Identity Scream Director Teases Sam’s Mom’s Identity
Entertainment4 months ago

Scream Director Teases Sam’s Mom’s Identity

Share our content or if you have any questions about an article, leave us a comment. TwitterFacebookGoogle+BufferLinkedInPin ItIn a recent...

ADVERTISEMENT