0

I have created a page:

http://mypage.com/paypal

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

http://mypage.com/paypal

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?

  • 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
1

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 );
    exit;
}

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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