Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:10:44+00:00 2026-06-12T00:10:44+00:00

I created a back link using the PHP http_referer for my website. It works

  • 0

I created a back link using the PHP http_referer for my website. It works basically but I would like to enable it only if the referer is a page with my domain. I thought about comparing the strings from the refering page and the current page but I did not find out how it could work.

This is my code:

    <?php // Back link to previous page.

    // If current page has been called by a hyperlink.
    if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] !='') echo '<a href="'.$_SERVER['HTTP_REFERER'].'">&laquo; Go back.</a>';

    // If current page has NOT been called by a hyperlink.
    else return;
    ?>

Can you give me any advise which PHP function I should use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:10:45+00:00Added an answer on June 12, 2026 at 12:10 am

    You could parse the url from $_SERVER['HTTP_REFERER'] and get the hostname & compare it with your own. So the function your looking for is parse_url():

    if(!empty($_SERVER['HTTP_REFERER']))
    {
        if(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) == $_SERVER['HTTP_HOST'])
        {
            echo '<a href="'.htmlentities($_SERVER['HTTP_REFERER']).'">&laquo; Go back.</a>';
        }
    }
    

    Also as $_SERVER['HTTP_REFERER'] can be set by the user its a good idea to htmlentities to stop any XSS.

    A safer idea as the PHP has handled if they entered from your domain, would be to just use some javascript in place of the link to send them back.

    echo '<a href="Javascript:window.history.back();">&laquo; Go back.</a>';

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A while back I created a lightbox plugin using jQuery that would load a
I would like to get a reference back to the function that created an
Is it impossible to create a browser back button, using a form or link,
I created several apps in iOS a while back using PhoneGap 1.0 and several
Some time back, I created two separate SharePoint projects in VS 2008; one using
I'm basically a front end designer and new to PHP and MySQL but I
In Jquery I would like to know how to trigger/click an a href... link
I would like to share via the facebook sharer link on image click on
I've created a Facebook fan page that works as a fan gate / like
I have successfully created a simple RSS feed, but entries keep coming back as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.