How to Get Referrer URLs in PHP
Have you ever wondered where the traffic of your website is coming from? Understanding which sources bring your site traffic carries a lot of weight in sketching out appropriate marketing plans and advertisement campaigns?
In this article, we’ll show you one of the simplest ways to detect your traffic source, getting referrer URLs in PHP.
To let you clearly get to know how referrer URLs can help, we’ll walk you through how important they are to your WordPress site.
How Important Are Referrer URLs to Your Site?A referrer URL is a hypertext link that whenever users click on it, will direct them to another certain webpage. It serves as a key factor in generating traffic and increasing the reliability of your website.
The more referrer links you have, the higher chance you can receive traffic. Imagine someone is surfing and finding your link under a statement or a fact. They will certainly click on that URL for more information.
Plus, a link from a site to another is a great indicator to tell search engines that the second website is displaying useful relevant content. If some reputable websites have linked to your pages, web crawlers will perceive your content as an informative and authoritative source. This leads to a high chance that your site will be indexed and shown up on the first search result page.
Since you know how beneficial referrer URLs are to a website, let’s discover how to get the referrer URLs in PHP.
How to Find Referrer URLs in PHP
Getting referrer URLs in PHP comes in handy in terms of determining the traffic sources of a website. Once you track down which sites bring you huge amounts of traffic, you can shape your marketing strategy more specifically and effectively. What’s more, you’re also able to identify which keywords are mostly used by visitors in different search engines to get to the site.
Looking for referrer URLs using PHP is such a cinch. There is a global variable in PHP that contains the referred URLs, called “$_SERVER.” The “$_SERVER” variable includes the “HTTP_REFERER” element that will return the referrer URLs.
The combining “$_SERVER[‘HTTP_REFERER’]” variable will display the complete URLs of the webpage that the current page is linked from.
With the following code snippet, you can check if a referrer URL exists and output it on your webpage:
<?php // Check if Referral URL exists if (isset($_SERVER['HTTP_REFERER'])) { // Store Referral URL in a variable $refURL = $_SERVER['HTTP_REFERER']; // Display the Referral URL on web page echo $refURL; } else { echo "No referer URL"; } ?>
In the codes above, the “$_SERVER[‘HTTP_REFERER’]” variable will show you the referrer page’s URL if:
- The link to your webpage appears on other webpages.
- Visitors click on those links to access your site.
In case users visit your pages by using bookmarks or manually typing the URLs, “HTTP_REFERER” will be empty. Therefore, you’ll see a message of “No referer URL” pop up.
Disadvantages of referrer links
The benefits of referrer links also lead to several drawbacks. People will leave spam links on your site without your permission. By applying this method, spammers can have their site rank higher on search engines without providing valuable content.
To block referrer spam, you can seek help from a third-party plugin. Although there are multiple options available on WordPress.org, finding the right one isn’t a simple task. We recommend Bad Behavior for blocking spam referrer links.
Another useful tool comes to Prevent Direct Access Gold to grant access to protected files based on referrer links. Touch on our blog Block Referrer Spam in WordPress on how to use these plugins.
Conclusion
Through this article, you’ve learned what referrer URLs are, their benefits to your site, and how to get them in PHP. If you know how to take advantage of Referrer URLs efficiently, they can help pave the way for your site to the first SERP.
If you still have questions about this topic, don’t hesitate to get in touch with us via the comment section below!