OK, I finally got PHP up and running. I installed Apache and MySQL as well. I figured out a whole lot, and got PHPMyAdmin on.
I’m following the Zend Paypal and PHP Article
[http://www.zend.com/zend/tut/tutorial-paypal.php]
Now whenever I create users under the Users table in the paypal_tutorial database, it wont allow me to log in with the user/pass that I specify. I can log in as root with no password. I am using the paypal_tutorial database and the tables which are created by following the tutorial. These are my scripts:
IPN.php
<?php
### LISTING OF ipn.php
define ("DBHOST", "localhost");
define ("DBNAME", "paypal_tutorial");
define ("DBUSER", "root");
define ("DBPASS", "");
### CONNECT TO THE DATABASE
function DatabaseConnect() {
if (!($mylink = mysql_connect(DBHOST, DBUSER, DBPASS))) {
echo mysql_error();
exit;
} //fi
mysql_select_db(DBNAME) or die(mysql_error());
} // end function
DatabaseConnect(); // this will automatically connect us
// below supported vals that paypal posts to us, this list is exhaustive.. but
// without notify_version and verify_sign NOTE: if in is not in this array, it
// is not going in the database.
$paypal_vals = array("item_name", "receiver_email", "item_number",
"invoice", "quantity", "custom", "payment_status",
"pending_reason", "payment_date", "payment_gross", "payment_fee",
"txn_id", "txn_type", "first_name", "last_name", "address_street",
"address_city", "address_state", "address_zip", "address_country",
"address_status", "payer_email", "payer_status", "payment_type",
"subscr_date", "period1", "period2", "period3", "amount1",
"amount2", "amount3", "recurring", "reattempt", "retry_at",
"recur_times", "username", "password", "subscr_id", "option_name1",
"option_selection1", "option_name2", "option_selection2",
"num_cart_items"
);
// build insert statement
while (list ($key, $value) = each ($HTTP_POST_VARS)) {
if (in_array ($key, $paypal_vals)) {
if (is_numeric($value)) {
$addtosql .= " $key=$value,";
} else {
$newval = urlencode($value);
$topost .= "&$key=$newval"; //used later in reposting
$value = addslashes($value);
$addtosql .= " $key='$value',";
} //fi
} //fi
$entirepost .= "[$key]='$value',";
} //wend
$entirepost = addslashes($entirepost); // just in case..
$addtosql = substr("$addtosql", 0, -1).";"; //chop trailing "," replace with ";"
$sql1 = "
INSERT INTO accounting_paypal
SET date=now(), entirepost='$entirepost',". $addtosql;
mysql_db_query(DBNAME, $sql1) or die($sql1);
// We could use this in a log, or to track which users have which payment.
$paypal_id = mysql_insert_id();
if ($HTTP_POST_VARS['payment_status'] == "Completed"
|| $HTTP_POST_VARS['payment_status'] == "Pending")
{
$username = $HTTP_POST_VARS['payer_email'];
$sql = "
UPDATE users
SET paid = 'Y'
WHERE username = '$username'
";
$result = mysql_db_query(DBNAME, $sql) or die($sql);
} //fi
### END LISTING OF ipn.php
?>
And als index.php.
<?php
### LISTING OF index.php
### first some definitions we will be using.
define ("DBHOST", "localhost");
define ("DBNAME", "paypal_tutorial");
define ("DBUSER", "root");
define ("DBPASS", "");
define("PAYPAL_USER", "[email protected]");
define("PPLINK", "https://www.paypal.com/xclick/business=".
PAYPAL_USER.
"&item_name=members_payment&item_number=1".
"&amount=10.00&no_note=1¤cy_code=USD");
// our login form for user logins
$SHOW_LOGIN_FORM = <<<ENDFORM
<br /><br />
<center><form method='post' action='$PHP_SELF'><table>
<tr>
<td>Username: </td>
<td><input name='username' type='text' value=''></td>
</tr>
<tr>
<td>Password: </td>
<td><input name='PASSWORD' type='password' value=''></td>
</tr>
<tr>
<td colspan='2' align='center'>
<input type='submit' value='Log In'>
</td>
</tr>
</table>
</form></center>
ENDFORM;
// a function to handle setting cookies.
function sec_setcookie($var, $val, $modify=3600)
{
$exp = gmstrftime("%A, %d-%b-%Y %H:%M:%S", time() + $modify);
$dom = $GLOBALS["HTTP_HOST"];
if (preg_match("/^(.*):(.*)$/", $dom, $arr)) {
print_r($arr);
$dom = $arr[1];
}
$parts = explode(".", $dom);
$dom = ".". $parts[count($parts)-2]. ".". $parts[count($parts) - 1];
setcookie($var, $val, time() + $modify,"/", $dom, 0);
${$var} = $val;
global ${$var};
} //end function
### CONNECT TO THE DATABASE
function DatabaseConnect()
{
if (!($mylink = mysql_connect(DBHOST, DBUSER, DBPASS))) {
echo mysql_error();
exit;
} //fi
mysql_select_db(DBNAME) or die(mysql_error());
} // end function
DatabaseConnect(); // this will automatically connect us
### NOW THE LOGIC
// first see if we have a post
if ($HTTP_POST_VARS['username'] && $HTTP_POST_VARS['password']) {
$sql = "
SELECT *
FROM users
WHERE username = '$username'
AND password = '$password'
";
$result = mysql_db_query(DBNAME, $sql);
if (mysql_num_rows($result) > 0) {
$info = mysql_fetch_assoc($result);
if ($info[paid] == "Y") {
sec_setcookie("username", $username);
sec_setcookie("password", $password);
} else {
echo "<center><font color=red><b>ERROR, ACCOUNT NOT PAID</b></font><br>
<a href=".PPLINK.">CLICK HERE</a> to pay for service.</center>";
die();
} //fi
} else {
sec_setcookie("count", $count + 1);
echo "<center><font color=red><b>ERROR IN LOGIN - SIGN UP FOR AN ACCOUNT FIRST</b></font></center>";
if ($count > 3) {
echo "<center><font color=red><b>TOO MANY ATTEMPTS, TRY LATER</b></font></center>";
} else {
echo $SHOW_LOGIN_FORM;
} //fi
die();
} //fi
} //fi
if($_COOKIE['username'] && $_COOKIE['password']) {
$sql = "
SELECT *
FROM users
WHERE username = '$username'
AND password = '$password'
";
$result = mysql_db_query(DBNAME, $sql);
if (mysql_num_rows($result) == 0) {
# clear the cookies
sec_setcookie("username", "");
sec_setcookie("password", "");
echo $SHOW_LOGIN_FORM;
die();
} //fi
} else {
echo $SHOW_LOGIN_FORM;
die();
} //fi
?>
HERE IS THE PAID FOR PAGE.
Is these something wrong in my code? Whenever I try to log in with any account, paid for or not, it tells me to sign up for an account.
Does anyone know where to find a script that will handle user registration?
Thanks for all of the help.
[/url][/code]