• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

PayPal Integration

Dan

Bullah
NLC
I am creating a member signup and login script for a client. He wants PayPal integrated into the form so when people submit register.php they are taken to PayPal to submit payment and then redirected back to login.php
I can't figure out how to do this.
Anyone got ideas?

Here is the register.php:

PHP:
<?php

session_start();
session_regenerate_id(true); // Generate new session id and delete old (PHP >= 5 only)

// registration
include_once("includes/functions.php");
include_once("includes/config.php");

// Check if the ALLOW_JOIN variable is set
if (!ALLOW_JOIN) exit($ALERT['PAGE_UNAV']);

// Inserts the given (username, password) pair into the database.
// Returns true on success, false otherwise.
function addNewUser($username, $password, $email){
	global $conn;
	/* Add slashes if necessary (for query) */
	if(!get_magic_quotes_gpc()) {
		$username = addslashes($username);
		$password = addslashes($password);
		$email = addslashes($email);
	}
	$q = "INSERT INTO ".DB_PREFIX."users VALUES ('', '$username', '$password', '$email', '".date('Y-m-d  H:i:s')."', '".$_SERVER['REMOTE_ADDR']."', '".date('Y-m-d  H:i:s')."')";
	return mysql_query($q,$conn);
}



// Display registration result page
if(isset($_SESSION['registered'])){

	// html
	include_once(HTML_PATH."html_register_result.php");

	unset($_SESSION['reguname']);
	unset($_SESSION['registered']);
	unset($_SESSION['regresult']);
	return;
}



// If the register form has been submitted: check for errors.
// No errors (count($alertArr) == 0)? Add record to database.
// Errors? Display error messages and show form again.
if(isset($_POST['subform'])){

	// clean up
	if ($_POST['user'])				$_POST['user'] = cleanString($_POST['user'], 30);
	if ($_POST['pass_field_1'])		$_POST['pass_field_1'] = cleanString($_POST['pass_field_1'], 30);
	if ($_POST['pass_field_2'])		$_POST['pass_field_2'] = cleanString($_POST['pass_field_2'], 30);
	if ($_POST['email'])			$_POST['email'] = cleanString($_POST['email'], 140);
	if ($_POST['pass1'])			$_POST['pass1'] = cleanString($_POST['pass1'], 40);
	if ($_POST['pass2'])			$_POST['pass2'] = cleanString($_POST['pass2'], 40);
	if ($_POST['salt'])				$_POST['salt'] = '';
	if ($_POST['key'])				$_POST['key'] = '';

	// check for errors
	$alertArr = array();

	if(!$_POST['user']) {
		$alertArr[] = $ALERT['USER_NO'];
	}
	
	if(strlen($_POST['user']) > 30) {
		$alertArr[] = $ALERT['USER_TOLONG'];
	}
	
	if($_POST['user'] && strlen($_POST['user']) < 6) {
		$alertArr[] = $ALERT['USER_TOSHORT'];
	}

	if(!$_POST['pass_field_1']) {
		$alertArr[] = $ALERT['PASS_NO'];
	}

	if($_POST['pass_1'] != $_POST['pass_2']) {
		$alertArr[] = $ALERT['PASS_DIFF'];
	}

	if(strlen($_POST['pass_field_1']) > 30) {
		$alertArr[] = $ALERT['PASS_TOLONG'];
	}
	
	if($_POST['pass_field_1'] && strlen($_POST['pass_field_1']) < 6) {
		$alertArr[] = $ALERT['PASS_TOSHORT'];
	}

	if(!$_POST['email']) {
		$alertArr[] = $ALERT['EMAIL_NO'];
	}
	
	if(strlen($_POST['email']) > 140) {
		$alertArr[] = $ALERT['EMAIL_TOLONG'];
	}
	
	if($_POST['email'] && !emailValid($_POST['email'])) {
		$alertArr[] = $ALERT['EMAIL_INVALID'];
	}
	
	if($_POST['email'] && emailExist($_POST['email'])) {
		$alertArr[] = $ALERT['EMAIL_TAKEN'];
	}

	if(usernameTaken($_POST['user'])) {
		$alertArr[] = $ALERT['USER_TAKEN'];
	}

	// Captcha
	if (CAPTCHA) {
		if (empty($_POST['validator']) || $_POST['validator'] != $_SESSION['rand_code']) {
			$alertArr[] = $ALERT['CAPTCHA'];
		}
		unset($_SESSION['rand_code']);
	}

	if (count($alertArr) == 0) {
		// Add the new account to the database
		// (password has already been encrypted using javascript)
		$_SESSION['reguname'] = $_POST['user'];
		$_SESSION['regresult'] = addNewUser($_POST['user'], $_POST['pass1'], $_POST['email']);
		$_SESSION['registered'] = true;
		$refresh = htmlentities($_SERVER[PHP_SELF]);
		exit(include_once(HTML_PATH."html_refresh.php")); // stop script
	}
}

$alert = displayAlert($alertArr);

if ($_POST['pass_field_1']) $_POST['pass_field_1'] = "";
if ($_POST['pass_field_2']) $_POST['pass_field_2'] = "";

// html sign-up form
include_once(HTML_PATH."html_register_form.php");
?>

Any guidance is always appreciated.
 
You need an IPN script if you want this to be done automatically.

The one I use is http://www.opendb.net/paypal_ipn.php

Read through the page and then read through the script. Basically there's a part in the script that checks if the product exists in the DB (and they're paying the right price for it), and checks if the payment went through. If all's OK, you can update some tables to say that the member paid.
 
You need an IPN script if you want this to be done automatically.

The one I use is http://www.opendb.net/paypal_ipn.php

Read through the page and then read through the script. Basically there's a part in the script that checks if the product exists in the DB (and they're paying the right price for it), and checks if the payment went through. If all's OK, you can update some tables to say that the member paid.

exactly what Colin said. --^
 
Back
Top