WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a page:


with a custom template that contains the code to grab the ipn response from paypal etc.

Now, I need to redirect users accidentally or on a purpose access


I want to allow that to only when a user is redirected from paypal url. e.g. if it contains http://paypal.comor https://paypal.com then it's ok, but all other access redirect to WP homepage.

How to do that?

share|improve this question
You would want to look at the response from paypal developer.paypal.com/webapps/developer/docs/classic/ipn/… check for the expected information. This isn't really related to WordPress you might be better asking this on stackoverflow. – Mark Davidson Sep 4 '13 at 14:16
@MarkDavidson Mark, I am asking for a WP build-in function or best practice to redirect a user if the referrer is not http://paypal.com...something.... Is it clearer now? – Derfder Sep 4 '13 at 14:19
Referrer can be spoofed very easily you'd really want to check the information provided in the response.In terms of redirect you would want to use wp_redirect codex.wordpress.org/Function_Reference/wp_redirect if you did want to check the referer I'm not aware of a WordPress native method to do this so you'd probably need to write something yourself. Using something like parse_url($_SERVER['HTTP_REFERER']); – Mark Davidson Sep 4 '13 at 14:26

What you do is you pass an argument to the Paypal's return URL. For example:

So your return URL may look like this:

$url = home_url();
$url = add_query_arg( array( 'paypal' => '8832002472223abc' ), $url );

$paypal_ipn = array(
     'return_url' => $url
     // rest of your ipn data

In your IPN template, you can have something like this:

if ( ! isset( $_GET['paypal'] ) || $_GET['paypal'] !== '8832002472223abc' ) {
    $url = home_url();
    wp_safe_redirect( $url );

So with that code, when anyone goes to your IPN template page will be redirected unless they have that key=>value combination.

share|improve this answer
Thanks, that looks fine. I will try it ;) – Derfder Sep 4 '13 at 15:06

Your Answer


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.