Software Distributor
Free Copy Protection
Software Downloads
Help>How To Perform On-Line Registration Using PHP
Software Distributor
Copy Protection
Menu
Info
Company
Resources
How To Perform On-Line Registration Using PHP

This is the PHP code for setting up a simple database that will allow you to register your customers. This is the PHP code and MySQL table used in the Sample Application for MySQL and PHP.

Watch out for some coding conversion errors when I converted this from PHP to HTML for display purposes. This occurs sometimes in certain browsers e.g. Netscape. You will see the ampersand sign followed by gt or lt when you should see a > or < character.

<html>
<body>
<title>
Sample Product Registration
</title>
<?PHP
$gpkstart = ""; // Global variables
$gpkend = "";

if ($submit) // Process the form - submit was pressed
{



$certificate = htmlspecialchars($certificate);
$cname = htmlspecialchars($cname);
$email = htmlspecialchars($email);
$name = htmlspecialchars($name);
$phone = htmlspecialchars($phone);
$url = htmlspecialchars($url);
$notes = htmlspecialchars($notes);
$true = True;
$false = False;
$validc = True;
$valide = True;
$validu = True;
$blank = "";
$validc = validate($certificate);
if ("$validc" !== "$true")
{
// echo "ERROR: Certificate is invalid\n\n";
?>
<Font face="arial" color="red"><B> ERROR: Certificate is invalid.
Certificate is case-sensitive.</B></Font><br><br>
<?PHP

}

$valide = verifyemailaddress($email, $level=2);
if ("$valide" !== "$true")
{
// echo "ERROR: E-mail address is invalid\n\n";
?>
<Font face="arial" color="red"><B> ERROR: E-mail address is
invalid.</B></Font><br><br>
<?PHP

}

if ("$url" == "$blank")
{
$validu = $true;
}
else
{
$validu = verifyurl( $url );
if ("$validu" !== "$true")
{
?>
<Font face="arial" color="red"><B> ERROR: URL is invalid.
Format is http://www.yourwebsite.com OR
www.yourwebsite.com</B></Font><br><br>
<?PHP
}
}


if ("$validc" == "$true")
if ("$valide" == "$true")
if ("$validu" == "$true")
$valid = $true;
else
$valid = $false;
else
$valid = $false;
else
$valid = $false;

if ("$valid" == "$true")
{

$status = addrecord($certificate,$cname,$email,
$name,$phone,$url,$notes);

if ("$status" == "$true")
{
$status = updaterecord($email);
if ("$status" == "$true")
{
listdatabase($certificate,$email,$name);
$comments = "The certificate number is case-sensitive
so ensure that your CAPS LOCK
are off.";
sendmail($name,$comments,$certificate,$email);
}
else
{
?>
<Font face="arial" color="red"><B> ERROR: A database
error
occurred. Data not entered into database. Please try again or
at a later time. If this
persists then send an
e-mail to <a href="mailto:techsupport@zappersoftware.com>Tech
Support.</a></B></Font>
<?PHP
}

}
else
{
// echo "ERROR: Data not entered into database. Please try
again.\n$\n'$result'\n'$query'";
?>
<Font face="arial" color="red"><B> ERROR: A database
error occurred. Data not entered into database. Please try again
or at a later time. If this persists then send an
e-mail to <a href="mailto:techsupport@zappersoftware.com>Tech
Support.</a></B></Font>
<?PHP
displayform($certificate,$cname,$email,$name,$phone,$url,$notes);
}
}
else
{
?>

<Font face="arial" color="red"><B> NOTE: Cannot submit
form due to errors.
<br><br> Please correct the errors and re-submit or
contact <a href="mailto:
techsupport@zappersoftware.com">tech support for
help.</a></B></Font><br><br>
<!--
<Font face="arial" color="red"><B> ERROR:
Required fields missing. Please enter
e-mail and certificate. If you enter a URL then please ensure that it is
correct.</B></Font>
-->
<?PHP

displayform($certificate,$cname,$email,$name,$phone,$url,$notes);

}

}



else // Display the form for the first time
{
displayform($certificate,$cname,$email,$name,$phone,$url,$notes);
} // end if

?>
<?PHP
function validate($certificate)
{
$True = True;
$False = False;
$retval = True;

if ("$certificate" == "ABCDEFGH")
// This should be another MySQL table used to validate certificates
$retval = $True;
else
$retval = $False;

return $retval;

}

function addrecord($certificate,$cname,$email,
$name,$phone,$url,$notes)
{
include("/PHPMyAdmin/_secure.php");
global $REMOTE_ADDR, $HTTP_REFERER;
$expected = 1; // Expect 1 row to be added
$link = @mysql_connect($mysql_server, $mysql_username,
$mysql_password);
mysql_select_db("Sample");
$query = "INSERT INTO ProductKey
(row,certificate,company_name,email_address,
contact_name,phone_number,
url,notes,remote_addr,http
_referer,product_key,license_key,datetime_added) VALUES
(0,'$certificate','$cname','$email','$name','$phone','$url','$notes',
'$REMOTE_ADDR','$HTTP_REFER
ER','00000100','BC510862',CURRENT_TIMESTAMP)";

$result = mysql_query($query);
mysql_close($link);
$True = True;
$False = False;
$retval = False;
if ("$result" == "$expected")
$retval = $True;
else
$retval = $False;

return $retval;
}

function updaterecord($email)
{
include("/PHPMyAdmin/_secure.php");

$expected = 1; // Expect 1 row to be updated
$link = @mysql_connect($mysql_server, $mysql_username,
$mysql_password);
mysql_select_db("Sample");
$query = "UPDATE ProductKey SET certificate='ABCDEFGH'
WHERE email_address='$email' AND
product_key='00000100' AND license_key='BC510862'";
$result = mysql_query($query);
mysql_close($link);
$True = True;
$False = False;
$retval = False;
if ("$result" == "$expected")
$retval = $True;
else
$retval = $False;

return $retval;
}

function displayform($certificate,$cname,$email,$name,
$phone,$url,$notes)
{
?>
<div align="center"><center>
<FORM method="post" action="<?PHP echo $PHP_SELF?>">
<table bordercolor="#c0c0c0" width="95%" cellpadding="4"
cellspacing="0" border="1">
<th bgcolor="lightyellow" valign="BOTTOM"
align="center" width="100%">
<Font face="impact,arial,verdana" color="#000000"
size="+2"><I> Zapper Software
- Sample </I></Font>
<br>
<br>
<Font face="arial,verdana" color="#2b82c7">
Enter Submission Details To Register
Product</Font>
</th>
<tr>

<td align="center">
<br>
<A href="product-key-rules.html"><Font
face="arial,verdana"
color="#CD0000"><B>Read the rules first

please.</b></font></A>
<br>
<br>
</td>
</tr>
<tr>
<td align="center">
<table border="0" width="100%" cellpadding="3"
cellspacing="0">
<tr>
<td align="right" valign="top"><font
face="arial,verdana"><b>Name or
Company Name</b></font></td>
<td align="left"><input type="text" size=35
name="cname" value="<?PHP echo
"$cname"; ?>"></td>
</tr>
<tr>
<td align="right" valign="top"><font
face="arial,verdana"><b>Certificate
Number</b></font></td>
<td align="left"><input type="text" size=8
name="certificate" value="<?PHP
echo "$certificate"; ?>" ></td>
</tr>
<tr>
<td align="right" valign="top"><font
face="arial,verdana"><b>E-mail
Address</b></font></td>
<td align="left"><input type="text" size=50
name="email" value="<?PHP echo
"$email"; ?>" ></td>
</tr>
<tr>
<td align="right" valign="top"><font
face="arial,verdana"><b>Contact
Name</b></font></td>
<td align="left"><input type="text" size=35
name="name" value="<?PHP echo
"$name"; ?>"></td>
</tr>
<tr>
<td align="right"><font face="arial,verdana"
><b>Phone
Number</b></font></td>
<td align="left"><input type="text" size=15
name="phone" value="<?PHP echo
"$phone"; ?>"></td>
</tr>
<tr>
<td align="right" valign="top"><font
face="arial,verdana"><b>URL</b></font></td>
<td align="left"><input type="text" size=50
name="url" value="<?PHP echo
"$url"; ?>"></td>
</tr>
<tr>
<td align="right" valign="top"><font
face="arial,verdana"><b>Notes</b></font></td>
<td align="left"><TEXTAREA cols=35 name="notes"
value="<?PHP echo "$notes";
?>" rows=4 ></TEXTAREA></td>
</tr>

<tr>
<td></td>
<td valign="top"><input type="Submit" name="submit"
value="Submit"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center></div></td>
</tr>
</table>
</form>
<!--
        
-->
<center>
<font face="arial,verdana" size="2"><b><i>Only the
certificate number and your
e-mail address are required fields.</i></b></font>

</center>
<br>
<center>
<font face="arial,verdana" size="2">
<b>NOTE: </b>The Passwords are sent to the e-mail address above.
</font>

</center>
<br>
<?PHP
}
?>

<?PHP
function listdatabase($certificate,$email,$name)

{
include("/PHPMyAdmin/_secure.php");

global $gpkstart, $gpkend;
$link = @mysql_connect($mysql_server, $mysql_username,
$mysql_password);
mysql_select_db("Sample");
$query = "SELECT * FROM ProductKey WHERE
email_address='$email' ORDER BY row";
$result = mysql_query($query);

echo "<center><b>Sample Product Registration Listing
</b></center>\n";

echo "<br>\n";
echo "<br>\n";
echo "<table border=1>\n";
echo "<tr><td>Certificate</td><td>Company
Name</td><td>E-Mail</td><td>Contact
Name</td><td>Phone</td><td>URL</td><td>
Notes</td><td>Product
Key</td><td>License Key </td></tr>\n";
while ($line = mysql_fetch_array($result))
{
printf("<tr><td>%s</td><td>%s</td><td>
%s</td><td>%s</td><t
d>%s</td><td>%s</td><td>%s</td><td>
%s</td><td>%s</td></t
r>\n", $line[1], $line[2], $line[3],$line[4],$line[5],
$line[6],$line[7],$line[10],$line[11]);
$certificate = $line[1];
$name = $line[4];
$gpkstart = $line[10];
$gpkend = $line[11];
}

echo "</table>\n";
echo "<br>\n";
echo "<br>\n";
echo "<center><b>End of Sample Product Registration
Listing</b></center>\n";
echo "<br>\n";

}

function sendmail($name,$comments,$certificate,$email)
{
global $gpkstart, $gpkend, $REMOTE_ADDR, $HTTP_REFERER;
if ("$name" == "")
$name = "Customer";
$subject = "Sample Product Registration";
$to ="techsupport@zappersoftware.com";
$message = "*** Sample Product Registration ***" . "\n\n"
. "Name: " . $name . "\n\n" .
"Email: " . $email . "\n\n" . "Comments: " . $comments .
"\n\n" . "Certificate Number: " .
$certificate . " (Enter in Sample Key/Certificate Number)" .
"\n\n" . "Product Key: " .
$gpkstart . " " . "\n\n" . "License Key: " . $gpkend . " " .
"\n\n" . "From IP Address: " .
$REMOTE_ADDR . "\n\n" . "Thank you. If you have any problems
then please reply to this e-mail
or contact techsupport@zappersoftware.com";
$eLog="/tmp/mailError.log";
//Get the size of the error log
//ensure it exists, create it if it doesn't
$fh= fopen($eLog, "a+");
fclose($fh);
$originalsize = filesize($eLog);

print ("Sending information (Product Registration added)
to $email</ br></ br>");
mail( $email, $subject, $message, "From: sales@zappersoftware.com");

/*
* NOTE: PHP caches file status so we need to clear
* that cache so we can get the current file size
*/
clearstatcache();
$finalsize = filesize($eLog);

//Check if the error log was just updated
echo "<p class=bodymd>Dear $name, please <B>cut and
paste</B> all of this
information. Please ensure that you enter the Certificate Number "
. $certificate . " EXACTLY as
it is printed here (this is case-sensitive) into the Sample Software
Key program.</p>";
if ($originalsize != $finalsize)
{
print "<p>There was a problem sending the mail. Please
ensure that you manually copy all
of the information regarding Product Registration. IMPORTANT:
Your Certificate Number is: " .
$certificate . "</p>";
}
else
{
echo "<p class=bodymd>E-mail has been sent to $email
with this information,
$name.</p>";
}

echo "<center><b>End of Sample Product Registration
</b></center>\n";

}

function verifyurl( $urladdr ){

$True = True;
$False = False;
$regexp =
"^(https?://)?(([0-9a-z_!~*'().&=+$%-]+:)?[0-9a-z_!~*'
().&=+$%-]+@)?(([0-9]{1,3}\.){3}[0-9]{1,3}
|([0-9a-z_!~*'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.
[a-z]{2,3})(:[0-9]{1,4})?((/?)|(/[0-9
a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";

if (eregi( $regexp, $urladdr )){
// No http:// at the front? lets add it.

if (!eregi( "^https?://", $urladdr )) $urladdr = "http://" . $urladdr;
// If it's a plain domain or IP there should be a / on the end
if (!eregi( "^https?://.+/", $urladdr )) $urladdr .= "/";
// If it's a directory on the end we should add the proper slash
// We should first make sure it isn't a file, query, or fragment
if ((eregi( "/[0-9a-z~_-]+$", $urladdr)) &&
(!eregi( "[\?;&=+\$,#]", $urladdr)))
$urladdr .= "/";
// return ($urladdr);
return $True;
}
else return $False; // The domain didn't pass the expression

} // END function verifyurl

/* VERIFY E-MAIL ADDRESS FUNCTION:
This function will verify an e-mail address through several layers.
You can choose to what degree it is checked:
1) Properly formatted
2) A server exists for the domain
3) The mail servers answers and verifies the user exists (default)

It will return either true or false, along with a status message
contained in the variable $verifyemailaddressinfo
*/

function verifyemailaddress( $emailaddr, $level=2)
{

$True = True;
$False = False;

global $verifyemailaddressinfo;
$verifyemailaddressinfo = "";
global $verifyemailaddresslevel;
$verifyemailaddresslevel = "0";

// Verifying E-Mail Format
// This regular expression allows for user@ip, user@domain.com,
user@sub.domains.com
$regexp =
"^[0-9a-z_\.-]+@(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z]
[0-9a-z-]*[0-9a-z]\.)+[a-z]{2,3})$";
if (!eregi( $regexp, $emailaddr )){
$verifyemailaddressinfo = "E-mail address not formed properly.";
// return false;
return $False;
}
$verifyemailaddresslevel = "1";
if ($level <= 1) {
$verifyemailaddressinfo = "E-mail address passed expression match";
// return true;
return $True;
}

// Lets split that email address up
list( $emailaccountname, $emailhostname ) = split( "@", $emailaddr, 2 );

// Confirming Mail Exchange server exists for domain, if it does not
// exist we will check for an ip as some servers may not use MX entries.
// The extra "." is needed when hosting on servers with old versions of bind
if (!getmxrr( ($emailhostname . "."), $mxhosts)){
$emailhostip = @gethostbyname( $emailhostname );
if ((!$emailhostip) || ($emailhostip == $emailhostname) && (!ereg(
"^([0-9]{1,3}\.){3}[0-9]{1,3}$", $emailhostname ))){
$verifyemailaddressinfo = "Could not find mail
server for $emailhostname";
return $False;
}
$mxhosts = array($emailhostip);
}
$verifyemailaddresslevel = "2";
if ($level == 2) {

$verifyemailaddressinfo = "Mail server found
for $emailhostname";
return $True;
}

// Querying the first MX server that answers
while ((list ($key, $mxserver) = each ($mxhosts)) && ($level == 3)) {
$fp = fsockopen( $mxserver, 25, &$errnum, &$errstr);
if ($fp) {

// Is the server ready? Lets wait for it (220)
set_socket_blocking( $fp, false );
$count1 = 0;

$count2 = 0;
$out = "";
do {
$out = fgets( $fp, 2500 );
if( ereg( "^220", $out )) {
$count1 = 0;
$out = "";
$count2++;
}
else if( ( $count2 > 0 ) && ( $out == "" )) { break; }
else $count1++;
if( $count1 == 9999 ) { break; }
// Prevents script from looping infinetly
} while( $out == "" );

// Lets say hello!
set_socket_blocking( $fp, true );
fputs( $fp, "HELO zappersoftware.com\n" );
// Change zappersoftware.com to $SERVER_NAME
$output = fgets( $fp, 2000 ); // output ignored

// try preforming a VRFY (rarely supported but more reliable)
fputs( $fp, "VRFY $emailaddr\n" );
$output = fgets( $fp, 2000 );
if (ereg ( "^250", $output )) {
$verifyemailaddresslevel = "3";
$verifyemailaddressinfo = "$emailaccountname
validated via VRFY - $output";
fputs( $fp, "QUIT\n" );
fclose( $fp );
return $True;
}
elseif (ereg ( "^550", $output )) {
$verifyemailaddressinfo = "$emailaccountname
invalidated via VRFY - $output";
fputs( $fp, "QUIT\n" );
fclose( $fp );
return $False;
}

// The VRFY didn't work. Now lets try RCPT TO:
else {
// First lets reset the server
fputs( $fp, "RSET\n" );
$output = fgets( $fp, 2000 ); // output ignored


// give a bogus "MAIL FROM:" header to the server
fputs( $fp, "MAIL FROM: <info@$emailhostname>\n" );
$output = fgets( $fp, 2000 ); // output ignored

// give RCPT TO: header for the email address we are testing
fputs( $fp, "RCPT TO: <$emailaddr>\n" );
$output = fgets( $fp, 2000 );
if ( ereg ( "^250", $output ) ) {
$verifyemailaddressinfo = "$emailaccountname validated
via RCPT TO -
$output";
$verifyemailaddresslevel = "3";
fputs( $fp, "QUIT\n" );
fclose( $fp );
return $True;
}
else {
$verifyemailaddressinfo = "$emailaccountname
invalidated via RCPT TO -
$output";
fputs( $fp, "QUIT\n" );
fclose( $fp );
return $False;
}
} // END RCPT TO: check

fclose( $fp );
} // END if ($fp)

$verifyemailaddressinfo = "All mail servers for $emailhostname
failed to respond.";
return $False;
} // END While mxhosts array search

$verifyemailaddressinfo = "You shouldn't see this...
If you can then something went wrong
with the verifyemailaddress function";
return $False;

} // END function verifyemailaddress

?>

</body>
</html>


Any questions, comments or concerns can be addressed to me at the Contact Us page.

Written by William H. Bradshaw
Get The FREE Software:
Registration Summary:

- On-line software key activition code iiss unique to each computer

- Setup ShareGuard Lock and a Lock Calliinng Program with Lock parameters

- Registration is fully automated

- Use a protected page and then issue a uusername, password and URL after the user purchases

- This approach offers the highest level oof software key protection

- Disadvantage: Users cannot migrate soffttware without your intervention

- Advantage: Nobody can ever redistributtee your software without registering

Products and Services for Windows and IBM

Software Distributor

Copyright © 1995-2003 Zapper Software 510862 B.C. Ltd. All rights reserved. Privacy Policy
1 1 1