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 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?

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

1 Answer 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.

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

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.