Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been searching for some WP specific way to detect any referrer. Have an idea? I know how to do that in PHP but I just want to know if there's some WP function to do that?

EDIT: here is what I 'm trying to test =>

$referer = wp_get_referer();
if (  strpos($referer ,'http://wordpress.org') !== false ) echo 'you come from wordpress.org';
share|improve this question

3 Answers 3

up vote 2 down vote accepted

The best way to check the referrer will depends of what are you trying to do. You can use wp_get_referer() or wp_get_original_referer(), but if you want to check the referer for security reasons you should definitely use other functions like check_admin_referer(), check_ajax_referer(), wp_referer_field() or other of the Wordpress Nonces related functions.

share|improve this answer
    
thanks, I know AJAX and security functions, already used several times but I was not aware WP can check referer in URL for SEO => trying to achieve some basic detection –  JMau Sep 8 '13 at 10:11
    
I've edited my thread to be more precise with my question –  JMau Sep 8 '13 at 10:14

You can get it using wp_get_referer() and wp_get_original_referer() functions.

share|improve this answer
    
Ok thanks, was expecting more details (you know kinda wiki) -> but this is this function so –  JMau Sep 8 '13 at 9:43
    
You can get more information for it from codex pages which i have linked with function names. –  Vinod Dalvi Sep 8 '13 at 9:44
    
never had to use these functions before, will try. –  JMau Sep 8 '13 at 9:49
2  
Difference between the 2 functions is that if a page post a form to itself wp_get_referer() return false, wp_get_original_referer() return the original referer. However, note that both make use of $_SERVER['HTTP_REFERER'] that, as said in php docs, "Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted." @JMau –  G. M. Sep 8 '13 at 15:57
    
@G.M. thanks. I know UA sniffing has some major drawbacks ! –  JMau Sep 9 '13 at 8:40

use wp_get_referer(); to Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively. for more info read codex

share|improve this answer
    
Is your answer different from my answer? –  Vinod Dalvi Sep 8 '13 at 9:42
    
you answered both in the same time –  JMau Sep 8 '13 at 9:42
    
not too much but we are both writing answer at same time, when i am going to click on submit answer button the notification was appear but i was late, clicked and answer was posted. –  Anjum Sep 8 '13 at 9:44
    
@JMau I thought i have answered a minute before. –  Vinod Dalvi Sep 8 '13 at 9:44
    
@Anjum It's ok. –  Vinod Dalvi Sep 8 '13 at 9:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.