Jump to content

Recommended Posts

I found these scripts here: http://net.tutsplus....ation-with-php/ and they doesn't seem to be working anymore. Seems a bit more then I can figure out how to correct. The broken script is the last one of the three it appears. If anyone knows what is wrong with the IPN please let me know, I am searching for a means to accept payment on a membership based website and I am not having any luck. Seems all the paid membership tutorials available that I have found are all broken or out of date.

 

The IPN when tested live with the correct settings doesn't do anything when paypal calls it. It doesn't create a user in the mysql database and it does not send any email.

 

These are of course just the default codes from the link above.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""[url="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/url]">
<html xmlns="[url="http://www.w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml[/url]">
<head>
<title>Nettuts.com | Purchase access to download area</title>
<link rel="stylesheet" type="text/css" media="All" href="css/style.css" />
</head>
<body>
<div id="wrap">
<h2>Purchase Access</h2>
<p>Please click the button below to receive login details for the download area. <br />
 Already have an account? <a href="login.php">Login</a> here.</p>

 Your PayPal Button Coder Here....
</div>
</body>
</html>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""[url="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/url]">
<html xmlns="[url="http://www.w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml[/url]">
<head>
<title>Nettuts.com | Login</title>
<link rel="stylesheet" type="text/css" media="All" href="css/style.css" />
</head>
<body>
<div id="wrap">

<?php

mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("DBName") or die(mysql_error());

if(isset($_POST['email']) && isset($_POST['password'])){
// Verify
$email = mysql_escape_string($_POST['email']);
$password = md5($_POST['password']);

$gUser = mysql_query("SELECT * FROM users WHERE email='".$email."' AND password='".$password."' LIMIT 1") or die(mysql_error());
$verify = mysql_num_rows($gUser);

if($verify > 0){
echo '<h2>Login Complete</h2>
	 <p>Click here to download our program</p>';
}else{
echo '<h2>Login Failed</h2>
	 <p>Sorry your login credentials are incorrect.';
}
}else{
?>
<h2>Login</h2>
<p>Please enter your login credentials to get access to the download area</p>

<form method="post" action="">
<fieldset>
<label for="email">Email:</label><input type="text" name="email" value="" />
<label for="password">Password:</label><input type="text" name="password" value="" />
<input type="submit" value="Login" />
</fieldset>
</form>

<?php
}
?>

</div>
</body>
</html>

 

IPN.php

 

<?php
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("DBName") or die(mysql_error());

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// PAYMENT VALIDATED & VERIFIED!
$email = $_POST['payer_email'];
$password = mt_rand(1000, 9999);
mysql_query("INSERT INTO users (email, password) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error());
$to	 = $email;
$subject = 'Download Area | Login credentials';
$message = '
Thank you for your purchase
Your account information
-------------------------
Email: '.$email.'
Password: '.$password.'
-------------------------

You can now login at [url="http://yourwebsite.com/PayPal/'"]http://yourwebsite.com/PayPal/'[/url];
$headers = 'From:noreply@downloadarea.com' . "\r\n";
mail($to, $subject, $message, $headers);

}
else if (strcmp ($res, "INVALID") == 0) {
// PAYMENT INVALID & INVESTIGATE MANUALY!
$to	 = [email="'admin@yourwebsite.com'"]'admin@yourwebsite.com'[/email];
$subject = 'Download Area | Invalid Payment';
$message = '
Dear Administrator,
A payment has been made but is flagged as INVALID.
Please verify the payment manualy and contact the buyer.
Buyer Email: '.$email.'
';
$headers = 'From:noreply@yourwebsite.com' . "\r\n";
mail($to, $subject, $message, $headers);
}
}
fclose ($fp);
}
?>

 

Thanks for taking a look. It's a really simple layout and would work perfectly for what I am doing... if it worked.

Edited by Nightasy
Link to comment
https://forums.phpfreaks.com/topic/269465-php-paypal-ipn-not-working/
Share on other sites

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

I don't like that part. Use

$_POST["cmd"] = "_notify-validate";
$req = http_build_query($_POST);

 

For debugging, have the script send you an email containing the $req and the $res (when it reads the value). See the invalid payment email code for an example how to do that. The $req should contain data that looks right to you and the $res should contain VERIFIED. Oh, and you should get an email in the first place.

Edited by requinix
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.