Jump to content

Need Help with registration system...


ricerocket

Recommended Posts

I have a registration system for my "free email" site which does a few functions like inserting info into the database, then it makes an http request to my cpanel which then creates the email account, if all goes well it's supposed to return with a success page but all it's doing is returning an error message like this:

CODE: SELECT ALL
Warning: fgets() [function.fgets]: SSL: fatal protocol error in /home/site/public_html/directory/reguser.php on line 88

 

but if the registration info is sent and the user is already taken I get this error message:

CODE: SELECT ALL
Warning: fgets() [function.fgets]: SSL: fatal protocol error in /home/site/public_html/directory/reguser.php on line 88

Warning: Cannot modify header information - headers already sent by (output started at /home/site/public_html/directory/reguser.php:88) in /home/site/public_html/directory/reguser.php on line 148

 

Below is the code for my processor page:

CODE: SELECT ALL
<?php

function check_email_address($email) {
  // First, we check that there's one @ symbol, and that the lengths are right
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    return false;
  }
  // Split it into sections to make life easier
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
     if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
      return false;
    }
  }  
  if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
    $domain_array = explode(".", $email_array[1]);
    if (sizeof($domain_array) < 2) {
        return false; // Not enough parts to domain
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
      if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
        return false;
      }
    }
  }
  return true;
}

// Check for Available Email Address
$requser = $_GET['username'];
if ( $requser == "" ) {
   $ermsg = "You must enter a username.";
}

include ("includes/db.inc.php");
$dbh=mysql_connect ("$dbhost", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$dbdatabase");

$result = mysql_query("SELECT id FROM useraccounts WHERE username='$requser'")
or die(mysql_error()); 
$row = mysql_fetch_array( $result );
$id = $row['id'];
if ( $id != "" ) {
   //echo "Username already taken";
   $ermsg = "Username is already taken.";
}

//Check for no blank fields
$reqpass = $_GET['password1'];
$regfname = $_GET['Fname'];
$reglname = $_GET['Lname'];
$reqsecquest = $_GET['securityquestion'];
$reqsecansw = $_GET['securityanswer'];
$reqaltemail = $_GET['altemail'];

if ( $reqpass == "" OR $regfname == "" OR $reglname == "" OR $reqsecquest == "" OR $reqsecansw == "" OR $reqaltemail == ""  ) {
   $ermsg = "All fields of the form must be completed.";
}

//Validate Alt Email
if (check_email_address($reqaltemail)) {
  //$ermsg = "";
} else {
   $ermsg = "Invalid alternate email address.";
}

if ( $ermsg == "" ) {
// Get Cpanel connection details
$result = mysql_query("SELECT username, password, ip, port FROM cpanel")
or die(mysql_error()); 
$row = mysql_fetch_array( $result );
$cpusername = $row['username'];
$cppassword = $row['password'];
$cpip = $row['ip'];
$cpport = $row['port'];

$cpurl = "https://$cpusername:$cppassword@$cpip:$cpport/frontend/$cpskin/mail/doaddpop.html?email=$requser&domain=$domain&password=$reqpass&quota=$quota";

$ok = TRUE;
$file = fopen ("$cpurl", "r");
if (!$file) {
$ok = FALSE;
$target = "error.php";
}
while (!feof ($file)) {
$line = fgets ($file, 1024);
if (ereg ("already exists!", $line, $out)) {
$ok = FALSE;
$target = "error.php";
}
}
fclose($file);
if ($ok) {
$target = "done.php";
$form_fields=array_keys($HTTP_POST_VARS);
$temp="\n";
while($field=array_pop($form_fields)){
$temp.=" $field : = $HTTP_POST_VARS[$field] \n";
}
return $line;

//mail($HTTP_POST_VARS['to'],"Free Email",$temp);
//Write to DB
$altemail = $_GET['altemail'];
$fname = $_GET['Fname'];
$lname = $_GET['Lname'];
$securityquestion = $_GET['securityquestion'];
$securityanswer = $_GET['securityanswer'];
$domainip = GetHostByName($REMOTE_ADDR);
$date = time();
$timestamp = date("F j, Y, g:i a",$date);

include ("includes/db.inc.php");
$dbh=mysql_connect ("$dbhost", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$dbdatabase");
mysql_query("INSERT INTO useraccounts (username, password, activated, altemail, fname, lname, securityquestion, securityanswer, ip, timestamp, quota) VALUES('$requser', '$reqpass', '1', '$altemail', '$fname', '$lname', '$securityquestion', '$securityanswer', '$domainip', '$timestamp', '$quota' ) ") or die(mysql_error());



//Mail to user

   $to = "<$altemail>\n";


mail($altemail, $subject,
    '<html><body>Hi '.$fname.$messageprt1.$requser.'@'.$domain.$messageprt2.$reqpass.$messageprt3.'</body></html>',
    "To: $to" .
    "From: $from\n" .
    "MIME-Version: 1.0\n" .
    "Content-type: text/html; charset=iso-8859-1");
    
// Mail to Admin
//Mail to admin new account notification
    $to = "<$adminnotifyaddy>\n";
    mail($adminnotifyaddy, 'New '.$domain.' Email Account Created',
    '<html><body>New email account created for <b>'.$domain.'</b><br><br>Email Address: <b>'.$requser.'@'.$domain.'</b><br>Password: <b>'.$reqpass.'</b><br>Quota: <b>'.$quota.' MB</b><br><br>First Name: <b>'.$fname.'</b><br>Last Name: <b>'.$lname.'</b><br>Security Question: <b>'.$securityquestion.'</b><br>Security Answer: <b>'.$securityanswer.'</b><br><br>Alternate Email: <b>'.$altemail.'</b><br><br>Created :<b>'.$timestamp.'</b><br>IP: <b>'.$domainip.'</b><br></body></html>',
    "To: $to" .
    "From: $from\n" .
    "MIME-Version: 1.0\n" .
    "Content-type: text/html; charset=iso-8859-1");
    /********************************************/  


}
$target = $target."?newemail=$requser&pass=$reqpass&name=$fname";
header("location:$target");

} else {
   $target = "error.php?ermsg=$ermsg";
   header("location:$target");
   
}

?>

 

If anyone can help me out with this it would be great

Link to comment
Share on other sites

hmm, this is just weird I've been trying everything, I was going to take out the error.php and done.php and just add in a few of those if strpost things. does anyone know how I would make it so that it returns the request content but doesn't show it? And also these errors are coming from the reguser.php page...

Link to comment
Share on other sites

Hi, I just read and tried what that post said and I'm still getting the errors. the same old errors, the weird thing is that everything works properly, and it inserts the info and creates the email but it shows those errors, the SSL one is fine because I was having problems with it before and I could fix it no matter what I did but I just wanted the done page to work ok. what would I change in the file I posted to get it to just show the done message inside it'self if the registration was a success? I've posted the done file:

<?php
/********** HWS RoundCube Auto Account Creation & Administration Addon **********/
/********** Designed & coded by tuney. Copyright 2006 License: GPL     **********/


include ("includes/db.inc.php");
?>
<LINK REL="stylesheet" HREF="<?php print $skin_path; ?>common.css" TYPE="text/css">
<style type="text/css">


a:hover {
color: #00197E;
}

a {
color: #00197E;
}

a:visited {
color: #00197E;
}

a:hover {
color: #00197E;

}
</style>
<?php

$newemail = $_GET['newemail'];
$pass = $_GET['pass'];
$name = $_GET['name'];
$logo_path = $skin_path . "images/roundcube_logo.gif";

echo "<table cellpadding='2' cellspacing='2' border='0'>";
echo "<tr>";
echo "<td><img src='$logo_path'></td>";
echo "</tr>";
echo "</table>";
echo "<table cellpadding='2' cellspacing='2' border='0' align='center'>";
echo "<tr>";
echo "<td colspan='2'><h2><font color='#00197E'>Account Creation Successful</font></h2>";
echo "<li>Your email account has been created.</li><li>Please check your new email address for information about your account</li><br><br><div align='center'><a href='javascript: history.go(-2);'>Login</a></div>";
echo "<br>";
echo "</td>";
echo "</tr>";


echo "</table>";


$newemail = $newemail."@".$domain;
$to = "<$newemail>\n";
mail($newemail, $subject,
    '<html><body>Hi '.$name.$messageprt1.$newemail.$messageprt2.$pass.$messageprt3,
    "To: $to" .
    "From: $from\n" .
    "MIME-Version: 1.0\n" .
    "Content-type: text/html; charset=iso-8859-1");




?>

 

 

 

Link to comment
Share on other sites

Ok I got most of everyhting working accept for part of my registration form processor. It inserts the info into the database, the error messages are working good, the success page works but it's just not creating the email account, I was using the part the creates the email by itself for a while but now that I've integrated it into the new system it's not working, and it will show the that email account was created fine but it really isn't. I was just wandering of someone could take a quick run through this code and see if you see anything wrong:

 

 

 

<?php 
    
   // database information 
   $dbhost = '--private--';       
   $dbuser = '--private--'; 
   $dbpassword = '--private--'; 
   $dbName = '--private--'; 

  // form information
  $fname = $_POST['fname'];
  $lname = $_POST['lname'];
  $staddress = $_POST['staddress'];
  $apt = $_POST['apt'];
  $city = $_POST['city'];
  $country = $_POST['country'];
  $state = $_POST['state'];
  $zipcode = $_POST['zipcode'];
  $phone = $_POST['phone'];
  $mm = $_POST['mm'];
  $dd = $_POST['dd'];
  $yyyy = $_POST['yyyy'];
  $sex = $_POST['sex'];
  $username = $_POST['username'];
  $password1 = $_POST['password1'];
  $password2 = $_POST['password2'];
  $squestion = $_POST['squestion'];
  $sanswer = $_POST['sanswer'];
  $sanswer2 = $_POST['sanswer2'];
  $altemail = $_POST['altemail'];

  // additional information

/***** Mailbox Quota *****/
$quota = "10";

/**** Welcome Mail to send to email address of user ****/
$from = "registrations@--private--.com";
$subject = "Welcome to --private-- Mail";
$messageprt1 = "<br><br>This is an automatically generated email from --private-- Mail<br><br>There is no need to reply to this email.<br><br>Welcome to your new --private-- Mail email account.<br><br>To access your account on the web go to <a href=\"http://www.--private--.com/members\">http://www.--private--.com/members</a> or click on the Webmail link on the --private-- Mail site.<br><br><b>Username - ";
$messageprt2 = "</b><br><b>Password - ";
$messageprt3 = "</b><br><br>To access your account using a POP3 or IMAP email client the settings you will need are as below....<br><b>Incoming (POP) Server - mail.--private--.com</b><br><b>Outgoing (SMTP) Server - mail.--private--.com</b><br><b>Username - your full --private--.com email address</b><br><br><br>--private-- Mail<br><a href=\"http://www.--private--.com\">http://www.--private--.com</a></body></html>";

/**** Domain ****/
$domain = "--private--.com";

/**** Password Recover Email ****/
$prfrom = "admin@--private--.com";
$prsubject = "Password Recovery";
$prmessageprt1 = "<html><body>This is an automatically generated email password recover message from --private-- Mail<br><br>There is no need to reply to this email.<br><br>Your requested login details are as below....<br><b>Username: ";
$prmessageprt2 = "</b><br><b>Password: ";
$prmessageprt3 = "</b><br><br>You can login to --private-- Mail email account from our main site <a href=\"http://www.--private--.com\">Here</a><br><br><br>Xolur Mail<br><a href=\"http://www.--private--.com\">http://www.--private--.com</a></body></html>";

/**** Admin Notification address for new email signup ****/
$adminnotifyaddy = "admin@--private--.com";

/**** Path to skin ****/
// Must have trailing slash
$skin_path = "../skins/default/";

/**** CPanel Skin ****/
$cpskin = "--private--";




// run through general checks
// make sure user filled in username
if ( $username == "" ) {
$ermsg = "You must enter a username.";
}

$dbh = mysql_connect ("$dbhost", "$dbuser", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$dbName");

// make sure username is available
$result = mysql_query("SELECT id FROM useraccounts WHERE username='$username'")
or die(mysql_error()); 
$row = mysql_fetch_array( $result );
$id = $row['id'];
if ( $id != "" ) {
//echo "Username already taken";
$ermsg = "Username is already taken.";
}

//Check for no blank fields

if ( $fname == "" OR $lname == "" OR $staddress == "" OR $apt == "" OR $city == "" OR $country == "" OR $state == "" OR $zipcode == "" OR $phone == "" OR $mm == "" OR $dd == "" OR $yyyy == "" OR $sex == "" OR $username == "" OR $password1 == "" OR $password2 == "" OR $squestion == "" OR $sanswer == "" OR $sanswer2 == "" OR $altemail == ""  ) {
$ermsg = "All fields of the registration must be completed.";
}

function check_email_address($email) {
  // First, we check that there's one @ symbol, and that the lengths are right
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    return false;
  }
  // Split it into sections to make life easier
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
     if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
      return false;
    }
  }  
  if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
    $domain_array = explode(".", $email_array[1]);
    if (sizeof($domain_array) < 2) {
        return false; // Not enough parts to domain
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
      if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
        return false;
      }
    }
  }
  return true;
}

//Validate Alternate Email
if (check_email_address($altemail)) {
  //$ermsg = "";
} else {
   $ermsg = "Invalid alternate email address.";
}

// creating the email account

if ( $ermsg == "" ) {

// required cpanel data
define( 'CPEMAIL_DOMAIN', '--private--.com'); // Cpanel domain
define( 'CPEMAIL_SSL', 0); // 0 = no SSL, 1 = Uses SSL
define( 'CPEMAIL_PORT', 2082); // usually the port is 2082 withought SSL and 2083 with SSL
define( 'CPEMAIL_THEME', '--private--'); // x is the default theme, others include: bluelagoon, x2, xmail, xcontroller, monsoon
define( 'CPEMAIL_QUOTA', 10); // email quota in Megabytes

// sensitive cpanel info
define( 'CPEMAIL_USER', '--private--'); // Cpanel Username
define( 'CPEMAIL_PASS', '--private--'); // Cpanel Password

if (isset($_POST['send'])) {

$password = $_POST['password1'];

$url = 'http'.(CPEMAIL_SSL ? 's' : '').'://'.CPEMAIL_USER.':'.CPEMAIL_PASS.'@'.CPEMAIL_DOMAIN.':'.CPEMAIL_PORT.'/frontend/'.CPEMAIL_THEME.'/mail/doaddpop.html';
$url .= '?email='.$username.'&domain='.CPEMAIL_DOMAIN.'&password='.$password.'&quota='.CPEMAIL_QUOTA;

// makes an fopen request to the url and returns the content
function http_request($url) {
ini_set('user_agent','MSIE 4\.0b2;'); // set user agent as IE browser

$txt = '';
if ($fp = fopen($url, 'r')) {
while( !feof($fp) ) {
$txt .= fread( $fp, 2082 );
}
fclose($fp);
}
return $txt;

// make the http request to cpanel, this is where the email is created
// this is just like the browser making the request, only php does it for the user
$txt = http_request( $url );

echo '<hr />';


}




//Write to DB
$domainip = GetHostByName($REMOTE_ADDR);
$date = time();
$timestamp = date("F j, Y, g:i a",$date);

$dbh=mysql_connect ("$dbhost", "$dbuser", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$dbName");
mysql_query("INSERT INTO useraccounts (username, password, activated, altemail, fname, lname, securityquestion, securityanswer, ip, timestamp, quota) VALUES('$username', '$password1', '1', '$altemail', '$fname', '$lname', '$squestion', '$sanswer', '$domainip', '$timestamp', '$quota' ) ") or die(mysql_error());  


//Mail to user

$to = "<$altemail>\n";


mail($altemail, $subject,
    '<html><body>Hi '.$fname.$messageprt1.$username.'@'.$domain.$messageprt2.$password1.$messageprt3.'</body></html>',
    "To: $to" .
    "From: $from\n" .
    "MIME-Version: 1.0\n" .
    "Content-type: text/html; charset=iso-8859-1");
    
// Mail to Admin
//Mail to admin new account notification
    $to = "<$adminnotifyaddy>\n";
    mail($adminnotifyaddy, 'New '.$domain.' Email Account Created',
    '<html><body>New email account created at <b>--private-- Mail</b><br><br>Email Address: <b>'.$username.'@'.$domain.'</b><br>Password: <b>'.$password1.'</b><br>Quota: <b>'.$quota.' MB</b><br><br>First Name: <b>'.$fname.'</b><br>Last Name: <b>'.$lname.'</b><br>Security Question: <b>'.$squestion.'</b><br>Security Answer: <b>'.$sanswer.'</b><br><br>Alternate Email: <b>'.$altemail.'</b><br><br>Created :<b>'.$timestamp.'</b><br>IP: <b>'.$domainip.'</b><br></body></html>',
    "To: $to" .
    "From: $from\n" .
    "MIME-Version: 1.0\n" .
    "Content-type: text/html; charset=iso-8859-1");
    /********************************************/  


}

$target = "http://www.--private--.com/members/done.php?newemail=$requser&pass=$reqpass&name=$fname";
header("location:$target");

} else {
$target = "http://www.--private--.com/members/error.php?ermsg=$ermsg";
header("location:$target");

}

?>

Link to comment
Share on other sites

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.