Jump to content

gasper000

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

gasper000's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have made a registration form that uses PHPMAILER to send the users a confirmation email whenever they finish creating their account. The email has a confirmation link that they have to open in order for their account to be active. Anyway, I have tested the whole process on my own pc using WAMP & everything is working fine. When I uploaded the files to my hosting account at godaddy & tested the form, it gives me the following error: "An error occurred in script 'blabla/class.smtp.php' on line 122: fsockopen() [function.fsockopen]: unable to connect to ssl://smtpout.secureserver.net:465 (Connection refused) Date/Time: 7-23-2009 03:30:14 Array ( [host] => ssl://smtpout.secureserver.net [port] => 465 [tval] => 10 [errno] => 0 [errstr] => )" I tried using different ports but it always gives me the same error. NOTE: (the same files & codes worked fine on my PC using WAMP .. I could connect to ssl://smtpout.secureserver.net .. sent the confirmation email & received with no problem. Also, I can send & receive emails from myemail@mydomain.com which is hosted by godaddy.) The error occurs ONLY WHEN USING THE REGISTRATION FORM WHICH SENDS A CONFIRMATION EMAIL AUTOMATICALLY WHEN THE USER HITS THE SUBMIT BUTTON. fsockopen is enabled. I have checked it. I did contact them & their answer was: "In order to be able to send email through our hosting accounts that we offer you must use the following relay server in your code: relay-hosting.secureserver.net You do not need to provide a user name and password for this relay server as it does not require authentication." I tried their solution but nothing changed. I read on their help files that fsockopen is enabled on port 80. I changed the port & now the error is: An error occurred in script 'blabla/class.smtp.php' on line 122: fsockopen() [function.fsockopen]: unable to connect to relay-hosting.secureserver.net:80 (Connection timed out) Date/Time: 7-24-2009 10:18:17 Array ( [host] => relay-hosting.secureserver.net [port] => 80 [tval] => 10 [errno] => 0 [errstr] => I read that if errno is = 0 then the error occurred before reaching the fsockopen function. but still can't figure out what's the problem is...!! how may the whole process work on my localhost using their servers but do not work when I upload the files on their hosting service ?!! I have been thinking, it could be a configuration or version problem as the whole process works fine on my pc using wamp. What do you think ?
  2. bliljerk101: Thank you very much for your time & effort. I just did what the tutorial has been telling. They used GET, that's why I used the same method. I used your codes after adding some few ,ines to call the DB details .. username ..etc..I didn't use the 2nd piece of codes to call the php file because I think the one that exists works fine & I don't wanna mess it up. Actually, it didn't work & when I try to open the php file in my browser, it says "Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in (sourcefile) on line 12 Error:" Below is the php file you wrote after adding my variables. <?php include("DB.php"); $tablename = 'tblTriviaAnswer'; mysql_connect ($host, $user, $pass); mysql_select_db ($database); $results=array(); $sql="SELECT * FROM `".$tablename."` WHERE `id`=".$_REQUEST[id]." LIMIT 1"; $results = mysql_query($sql, $link) or die('Error: ' . mysql_error()); while($a_row = mysql_fetch_array($results, MYSQL_ASSOC)) array_push($results, $a_row); if(count($results)){ echo('strAnswerList='.$results[0][answerText]); }else{ echo('Sorry - no result found'); } ?> What do you think ?
  3. It receives the data through the following link varTriviaSend.sendAndLoad("http://localhost/FlashDB/gettriviaquestion.php",varTriviaReceive,"GET"); The tutorial also included the following paragraph: As you can see, the data is URL encoded so that it can be properly imported into Flash. The first link will pull the number of questions found in the database, held in the qCount variable. The second link is called when the application randomly chooses the next question to retrieve. The data includes currentQ, answerList, and correctList. An errorMsg element is included on each page as well. If an error occurs loading the data, the errorMsg variable will be populated. Otherwise, just the items listed above will be displayed on the respective pages. The answerList and correctList data lists are actually pipe-delimited (‘|’) lists that allow the application to quickly split the list of items into an array, using the split method of the array object in Flash. Again, since the application will continue to make calls to the database application, it needs to use the remote server demonstrated in the code below unless you develop and host your own application to retrieve the data. If you wish to develop your own script, be sure that your application formats the data properly. For this application, I use ASP.NET to retrieve data from a multiple data tables. Is it helpful ?
  4. I have been developing a flash trivia using some tutorial. Everything went fine & I have added some new features to the trivia. The tutorial provides you with a url link to their database in order for you to test your trivia. They used ASP.NET as a way to load & display questions from their DB. Now I should create my own trivia questions & answers and store them in my own DB. The tutorial teaches you how to develop the flash trivia but they didn't mention how to make the ASP.NET file to link the DB to the flash trivia. As I never used ASP.NET before, I thought I would use PHP & MySQL instead. I created my own DB, inserted some random questions & answers and wrote the php code. When I try to test the flash trivia using my DB & the php file I have wrote, it doesn't seem to work. The flash trivia file is working normally but the questions & answers are not loaded from the MySQL DB. I have included below the ActionScript I use (Working Fine) Plus PHP file (doesn't seem to be working) & screen shots of the MySQL DB. ActionScript -Frame 1- //Stop the timeline stop(); //Determine the number of questions in the database var numQCount:Number; //Create trivia data receiver objects var varTriviaCount:LoadVars = new LoadVars(); //Load the data from the external web application varTriviaCount.load("http://localhost/FlashDB/gettriviaquestioncount.php"); //Once the data loads from remote server, get the count varTriviaCount.onLoad = function(blnSuccess:Boolean):Void { //See if data was loaded if(blnSuccess){ //Parse the data returned numQCount = varTriviaCount.qCount; } else { //Display an error trace("Error occurred on LoadVars"); } }; //When the Faceoff button is clicked, go to the trivia game btnLaunch.onRelease = function():Void { gotoAndStop(10); }; ActionScript -Frame 10- //Initialize trivia variables var numCurrentQ:Number = 1; var numCurrentScore:Number = 0; var numTimerVal:Number = 10; var numRandomQ:Number; var strCurrentQ:String; var arrQuestionList:Array = new Array(); var strAnswerList:String; var strCorrectList:String; var strAnswerText:String; var strCorrectAnswer:String; var arrAnswerText:Array = new Array(); var arrCorrectAnswer:Array = new Array(); var numCorrectAnswer:Number; //Start the trivia quiz getNextQuestion(); function getNextQuestion(){ //Initialize grades txtGradeC1._visible = false; txtGradeC2._visible = false; txtGradeC3._visible = false; txtGradeC4._visible = false; txtGradeW1._visible = false; txtGradeW2._visible = false; txtGradeW3._visible = false; txtGradeW4._visible = false; //Get a random number to determine current question numRandomQ = Math.floor(Math.random()*numQCount-1) + 1; //Determine if this question has been asked var blnNewQuestion:Boolean = true; //See if this is the first question if(numCurrentQ!=1){ //This is not the first question for(z=0;z<arrQuestionList.length;z++){ if(numRandomQ==arrQuestionList[z]){ //This question has already been asked blnNewQuestion = false; } } } //See if this question has been asked if(blnNewQuestion){ //Add the current question number to the list of asked questions arrQuestionList.push(numRandomQ); //Create trivia data sender & receiver objects var varTriviaSend:LoadVars = new LoadVars(); var varTriviaReceive:LoadVars = new LoadVars(); //Load the data from the external web application varTriviaSend.questionNum = numRandomQ; //varTriviaSend.send("http://localhost/FlashDB/gettriviaquestion.php","_blank","GET"); varTriviaSend.sendAndLoad("http://localhost/FlashDB/gettriviaquestion.php",varTriviaReceive,"GET"); //Once the data loads from remote server, build the question/answer display varTriviaReceive.onLoad = function(blnSuccess:Boolean):Void { //See if data was loaded if(blnSuccess){ //Parse the data returned //Set the question and answer text strCurrentQ = varTriviaReceive.currentQ; txtQuestion.text = strCurrentQ; //Set the answers strAnswerList = varTriviaReceive.answerList; arrAnswerText = strAnswerList.split("|"); txtAnswer1.text = arrAnswerText[0]; txtAnswer2.text = arrAnswerText[1]; txtAnswer3.text = arrAnswerText[2]; txtAnswer4.text = arrAnswerText[3]; //Unhide the buttons btnAnswer1._visible = true; btnAnswer2._visible = true; btnAnswer3._visible = true; btnAnswer4._visible = true; //Unhide the incorrect answers txtAnswer1._visible = true; txtAnswer2._visible = true; txtAnswer3._visible = true; txtAnswer4._visible = true; //Determine the correct answer strCorrectList = varTriviaReceive.correctList; arrCorrectAnswer = strCorrectList.split("|"); for(y=0;y<arrCorrectAnswer.length;y++){ if(arrCorrectAnswer[y]==1){ numCorrectAnswer = y+1; } } } else { //Display an error trace("Error occurred on LoadVars"); } } //Set the question number/score display txtQNum.text = numCurrentQ; txtScore.text = numCurrentScore; txtTimer.text = numTimerVal; btnNext._visible = false; //Run the countdown timer countDown = function () { numTimerVal--; txtTimer.text = numTimerVal; if (numTimerVal == 0) { clearInterval(timer); noAnswer(); btnNext._visible = true; } }; timer = setInterval(countDown, 1000); } else { getNextQuestion(); } } //When the user clicks an answer button, determine if it is correct btnAnswer1.onRelease = function():Void { //stop the timer clearInterval(timer); //Unhide the 'Next' button btnNext._visible = true; //See if answer is correct if(numCorrectAnswer == 1){ //Answer is correct numCurrentScore = numCurrentScore + (numTimerVal * 100); txtScore.text = numCurrentScore //Set the grades txtGradeC1._visible = true; //Hide the buttons btnAnswer1._visible = false; btnAnswer2._visible = false; btnAnswer3._visible = false; btnAnswer4._visible = false; //Hide the incorrect answers txtAnswer2._visible = false; txtAnswer3._visible = false; txtAnswer4._visible = false; } else { //Answer is not correct //Hide the buttons btnAnswer1._visible = false; btnAnswer2._visible = false; btnAnswer3._visible = false; btnAnswer4._visible = false; //Set the grades txtGradeW1._visible = true; //Hide the incorrect answers if(numCorrectAnswer != 2){ txtAnswer2._visible = false; } else { //Set the grades txtGradeC2._visible = true; } if(numCorrectAnswer != 3){ txtAnswer3._visible = false; } else { //Set the grades txtGradeC3._visible = true; } if(numCorrectAnswer != 4){ txtAnswer4._visible = false; } else { //Set the grades txtGradeC4._visible = true; } } } //When the user clicks an answer button, determine if it is correct btnAnswer2.onRelease = function():Void { //stop the timer clearInterval(timer); //Unhide the 'Next' button btnNext._visible = true; //See if answer is correct if(numCorrectAnswer == 2){ //Answer is correct numCurrentScore = numCurrentScore + (numTimerVal * 100); txtScore.text = numCurrentScore //Set the grades txtGradeC2._visible = true; //Hide the buttons btnAnswer1._visible = false; btnAnswer2._visible = false; btnAnswer3._visible = false; btnAnswer4._visible = false; //Hide the incorrect answers txtAnswer1._visible = false; txtAnswer3._visible = false; txtAnswer4._visible = false; } else { //Answer is not correct //Hide the buttons btnAnswer1._visible = false; btnAnswer2._visible = false; btnAnswer3._visible = false; btnAnswer4._visible = false; //Set the grades txtGradeW2._visible = true; //Hide the incorrect answers if(numCorrectAnswer != 1){ txtAnswer1._visible = false; } else { //Set the grades txtGradeC1._visible = true; } if(numCorrectAnswer != 3){ txtAnswer3._visible = false; } else { //Set the grades txtGradeC3._visible = true; } if(numCorrectAnswer != 4){ txtAnswer4._visible = false; } else { //Set the grades txtGradeC4._visible = true; } } } //When the user clicks an answer button, determine if it is correct btnAnswer3.onRelease = function():Void { //stop the timer clearInterval(timer); //Unhide the 'Next' button btnNext._visible = true; //See if answer is correct if(numCorrectAnswer == 3){ //Answer is correct numCurrentScore = numCurrentScore + (numTimerVal * 100); txtScore.text = numCurrentScore //Set the grades txtGradeC3._visible = true; //Hide the buttons btnAnswer1._visible = false; btnAnswer2._visible = false; btnAnswer3._visible = false; btnAnswer4._visible = false; //Hide the incorrect answers txtAnswer1._visible = false; txtAnswer2._visible = false; txtAnswer4._visible = false; } else { //Answer is not correct //Hide the buttons btnAnswer1._visible = false; btnAnswer2._visible = false; btnAnswer3._visible = false; btnAnswer4._visible = false; //Set the grades txtGradeW3._visible = true; //Hide the incorrect answers if(numCorrectAnswer != 1){ txtAnswer1._visible = false; } else { //Set the grades txtGradeC1._visible = true; } if(numCorrectAnswer != 2){ txtAnswer2._visible = false; } else { //Set the grades txtGradeC2._visible = true; } if(numCorrectAnswer != 4){ txtAnswer4._visible = false; } else { //Set the grades txtGradeC4._visible = true; } } } //When the user clicks an answer button, determine if it is correct btnAnswer4.onRelease = function():Void { //stop the timer clearInterval(timer); //Unhide the 'Next' button btnNext._visible = true; //See if answer is correct if(numCorrectAnswer == 4){ //Answer is correct numCurrentScore = numCurrentScore + (numTimerVal * 100); txtScore.text = numCurrentScore //Set the grades txtGradeC4._visible = true; //Hide the buttons btnAnswer1._visible = false; btnAnswer2._visible = false; btnAnswer3._visible = false; btnAnswer4._visible = false; //Hide the incorrect answers txtAnswer1._visible = false; txtAnswer2._visible = false; txtAnswer3._visible = false; } else { //Answer is not correct //Hide the buttons btnAnswer1._visible = false; btnAnswer2._visible = false; btnAnswer3._visible = false; btnAnswer4._visible = false; //Set the grades txtGradeW4._visible = true; //Hide the incorrect answers if(numCorrectAnswer != 1){ txtAnswer1._visible = false; } else { //Set the grades txtGradeC1._visible = true; } if(numCorrectAnswer != 2){ txtAnswer2._visible = false; } else { //Set the grades txtGradeC2._visible = true; } if(numCorrectAnswer != 3){ txtAnswer3._visible = false; } else { //Set the grades txtGradeC3._visible = true; } } } //Set the display when no answer is selected function noAnswer(){ //Hide all the answer buttons btnAnswer1._visible = false; btnAnswer2._visible = false; btnAnswer3._visible = false; btnAnswer4._visible = false; //Hide the incorrect answers if(numCorrectAnswer != 1){ txtAnswer1._visible = false; } else { txtGradeC1._visible = true; } if(numCorrectAnswer != 2){ txtAnswer2._visible = false; } else { txtGradeC2._visible = true; } if(numCorrectAnswer != 3){ txtAnswer3._visible = false; } else { txtGradeC3._visible = true; } if(numCorrectAnswer != 4){ txtAnswer4._visible = false; } else { txtGradeC4._visible = true; } } //When the user clicks the 'Next' button, go to the next question btnNext.onRelease = function():Void { //See if this is the last question if(numCurrentQ < 10){ //Not the last question, pull next question numCurrentQ++; numTimerVal = 10; getNextQuestion(); //Erase the grades txtGradeC1._visible = false; txtGradeC2._visible = false; txtGradeC3._visible = false; txtGradeC4._visible = false; txtGradeW1._visible = false; txtGradeW2._visible = false; txtGradeW3._visible = false; txtGradeW4._visible = false; } else { //This is the last question, jump to frame 20 gotoAndStop(20); } } PHP Files 1. DB.php <?php $host = 'localhost'; $user = 'username'; $pass = 'password'; $database = 'databasename'; ?> 2. <?php include("DB.php"); $table = 'tblTriviaAnswer'; mysql_connect ($host, $user, $pass); mysql_select_db ($database); $result = mysql_query ( "SELECT * FROM `tbltriviaanswer`"); $newresult = mysql_query ("SELECT * FROM `tbltriviaquestion`"); $i = 1; while ( $i <= 10){ $row = mysql_fetch_array($result); extract($row); echo "$answerText"; echo "$correctAnswer"; $i = $i + 1; } $j = 1; while ( $j <= 10){ $row = mysql_fetch_array($newresult); extract($row); echo "$questionNum"; $j = $j + 1; } ?> MySQL DB ScreenShots One Last thing is the DB ScreenShot that was included with the tutorial: Do you have any ideas how can I edit the PHP file in order for the trivia to load the questions & answers ?
  5. I'm trying to clean & organize my codes in order to make it easier to edit. I started by changing the css from inline to an external file. As it's the first time to use external css, I'm facing some problems. I searched online but still can't solve them. First problem is that I have to use padding in order to be able to display the image. If I remove the padding tags, the image does not show. Second problem occurs only in IE. Well, when I try to use opacity it works fine with Firefox & Opera but it does not have any effect when using IE. Also, the absolute positioning does not work in any browser. I have included the codes below. index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link rel="stylesheet" type="text/css" href="test.css" /> </head> <body> <div name="imagetest" id="imagetest"></div> </body> </html> test.css body {background-image: url('image1.jpg'); background-repeat: no-repeat; background-attachment: fixed;} #imagetest { background-image: url(images/image2.gif); background-repeat: no-repeat; background-position:center top; position: relative; top: 50px; padding-top: 455px; filter: alpha(opacity=80); opacity:0.8; z-index: 9; } Note: All these problems occur ONLY WHEN USING EXTERNAL CSS..Everything works smoothly when using inline css. Any ideas ?
  6. I have got a free working captcha from www.white-hat-web-design.co.uk. I tried it & it works fine. I modified some variables so I can insert it into my form. Even after I modified it ..It's still working fine. When I inserted it into my form it partly worked. As when the user leaves the captcha field empty, it asks him/her to re-enter the captcha again & stops sending the form..This is fine but if the user enters any characters in the captcha field..it validates them whatever the characters are ... it doesn't matter if they match or not. I included the codes of the working captcha alone, the partly working captcha after being inserted in the form & the codes for generating the image. I want to know where the error is. Working Captcha <?php session_start(); if( isset($_POST['submit'])) { if( $trimmed['Captcha'] == $_POST['Captcha'] && !empty($trimmed['Captcha'] ) ) { // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. echo 'Thank you. Your message said "'.$_POST['message'].'"'; unset($trimmed['Captcha']); } else { // Insert your code for showing an error message here echo 'Sorry, you have provided an invalid security code'; } } else { ?> <form action="form.php" method="post"> <label for="name">Name: </label><input type="text" name="name" id="name" /><br /> <label for="email">Email: </label><input type="text" name="email" id="email" /><br /> <label for="message">Message: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br /> <img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br /> <label for="Captcha">Security Code: </label><input id="Captcha" name="Captcha" type="text" /><br /> <input type="submit" name="submit" value="Submit" /> </form> <?php } ?> Partly Working // Check for a Captcha: if( isset($_POST['submit'])) { if ($trimmed['Captcha'] == $_POST['Captcha'] && !empty($trimmed['Captcha'])) { $ccap = mysqli_real_escape_string ($dbc, $trimmed['Captcha']); echo "Working Fine"; unset($trimmed['Captcha']); } else { echo "Not Working"; } } The Image Generation Codes <?php session_start(); /* * File: CaptchaSecurityImages.php * Author: Simon Jarvis * Copyright: 2006 Simon Jarvis * Date: 03/08/06 * Updated: 07/02/07 * Requirements: PHP 4/5 with GD and FreeType libraries * Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html * */ class CaptchaSecurityImages { var $font = 'monofont.ttf'; function generateCode($characters) { /* list all possible characters, similar looking characters and vowels have been removed */ $possible = '23456789bcdfghjkmnpqrstvwxyz'; $code = ''; $i = 0; while ($i < $characters) { $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1); $i++; } return $code; } function CaptchaSecurityImages($width='120',$height='40',$characters='6') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for( $i=0; $i<($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } /* generate random lines in background */ for( $i=0; $i<($width*$height)/150; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $trimmed['Captcha'] = $code; } } $width = isset($_GET['width']) ? $_GET['width'] : '120'; $height = isset($_GET['height']) ? $_GET['height'] : '40'; $characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6'; $captcha = new CaptchaSecurityImages($width,$height,$characters); ?> One more thing I want to know is how to add a button that refreshes the image when clicked without refreshing the whole page in case the image was not clear.
  7. smtp.php <?php /** Error: Failed to create a Net_SMTP object */ define('PEAR_MAIL_SMTP_ERROR_CREATE', 10000); /** Error: Failed to connect to SMTP server */ define('PEAR_MAIL_SMTP_ERROR_CONNECT', 10001); /** Error: SMTP authentication failure */ define('PEAR_MAIL_SMTP_ERROR_AUTH', 10002); /** Error: No From: address has been provided */ define('PEAR_MAIL_SMTP_ERROR_FROM', 10003); /** Error: Failed to set sender */ define('PEAR_MAIL_SMTP_ERROR_SENDER', 10004); /** Error: Failed to add recipient */ define('PEAR_MAIL_SMTP_ERROR_RECIPIENT', 10005); /** Error: Failed to send data */ define('PEAR_MAIL_SMTP_ERROR_DATA', 10006); /** * SMTP implementation of the PEAR Mail interface. Requires the Net_SMTP class. * @access public * @package Mail * @version $Revision: 1.28 $ */ class Mail_smtp extends Mail { /** * SMTP connection object. * * @var object * @access private */ var $_smtp = null; /** * The SMTP host to connect to. * @var string */ var $host = 'smtp.gmail.com'; /** * The port the SMTP server is on. * @var integer */ var $port = 465; /** * Should SMTP authentication be used? * * This value may be set to true, false or the name of a specific * authentication method. * * If the value is set to true, the Net_SMTP package will attempt to use * the best authentication method advertised by the remote SMTP server. * * @var mixed */ var $auth = true; /** * The username to use if the SMTP server requires authentication. * @var string */ var $username = 'my_username_at_google_goes_here'; /** * The password to use if the SMTP server requires authentication. * @var string */ var $password = 'my_password'; /** * Hostname or domain that will be sent to the remote SMTP server in the * HELO / EHLO message. * * @var string */ var $localhost = 'smtp.gmail.com'; /** * SMTP connection timeout value. NULL indicates no timeout. * * @var integer */ var $timeout = null; /** * Whether to use VERP or not. If not a boolean, the string value * will be used as the VERP separators. * * @var mixed boolean or string */ var $verp = false; /** * Turn on Net_SMTP debugging? * * @var boolean $debug */ var $debug = false; /** * Indicates whether or not the SMTP connection should persist over * multiple calls to the send() method. * * @var boolean */ var $persist = false; /** * Constructor. * * Instantiates a new Mail_smtp:: object based on the parameters * passed in. It looks for the following parameters: * host The server to connect to. Defaults to localhost. * port The port to connect to. Defaults to 25. * auth SMTP authentication. Defaults to none. * username The username to use for SMTP auth. No default. * password The password to use for SMTP auth. No default. * localhost The local hostname / domain. Defaults to localhost. * timeout The SMTP connection timeout. Defaults to none. * verp Whether to use VERP or not. Defaults to false. * debug Activate SMTP debug mode? Defaults to false. * persist Should the SMTP connection persist? * * If a parameter is present in the $params array, it replaces the * default. * * @param array Hash containing any parameters different from the * defaults. * @access public */ function Mail_smtp($params) { if (isset($params['smtp.gmail.com'])) $this->host = $params['smtp.gmail.com']; if (isset($params['465'])) $this->port = $params['465']; if (isset($params['true'])) $this->auth = $params['true']; if (isset($params['my_username_at_google_goes_here'])) $this->username = $params['my_username_at_google_goes_here']; if (isset($params['my_password'])) $this->password = $params['my_password']; if (isset($params['smtp.gmail.com'])) $this->localhost = $params['smtp.gmail.com']; if (isset($params['timeout'])) $this->timeout = $params['timeout']; if (isset($params['verp'])) $this->verp = $params['verp']; if (isset($params['debug'])) $this->debug = (boolean)$params['debug']; if (isset($params['persist'])) $this->persist = (boolean)$params['persist']; register_shutdown_function(array(&$this, '_Mail_smtp')); } /** * Destructor implementation to ensure that we disconnect from any * potentially-alive persistent SMTP connections. */ function _Mail_smtp() { $this->disconnect(); } /** * Implements Mail::send() function using SMTP. * * @param mixed $recipients Either a comma-seperated list of recipients * (RFC822 compliant), or an array of recipients, * each RFC822 valid. This may contain recipients not * specified in the headers, for Bcc:, resending * messages, etc. * * @param array $headers The array of headers to send with the mail, in an * associative array, where the array key is the * header name (e.g., 'Subject'), and the array value * is the header value (e.g., 'test'). The header * produced from those values would be 'Subject: * test'. * * @param string $body The full text of the message body, including any * Mime parts, etc. * * @return mixed Returns true on success, or a PEAR_Error * containing a descriptive error message on * failure. * @access public */ function send($recipients, $headers, $body) { include_once 'Net/SMTP.php'; /* If we don't already have an SMTP object, create one. */ if (is_object($this->_smtp) === false) { $this->_smtp =& new Net_SMTP($this->host, $this->port, $this->localhost); /* If we still don't have an SMTP object at this point, fail. */ if (is_object($this->_smtp) === false) { return PEAR::raiseError('Failed to create a Net_SMTP object', PEAR_MAIL_SMTP_ERROR_CREATE); } /* Configure the SMTP connection. */ if ($this->debug) { $this->_smtp->setDebug(true); } /* Attempt to connect to the configured SMTP server. */ if (PEAR::isError($res = $this->_smtp->connect($this->timeout))) { $error = $this->_error('Failed to connect to ' . $this->host . ':' . $this->port, $res); return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_CONNECT); } /* Attempt to authenticate if authentication has been enabled. */ if ($this->auth) { $method = is_string($this->auth) ? $this->auth : ''; if (PEAR::isError($res = $this->_smtp->auth($this->username, $this->password, $method))) { $error = $this->_error("$method authentication failure", $res); $this->_smtp->rset(); return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_AUTH); } } } $this->_sanitizeHeaders($headers); $headerElements = $this->prepareHeaders($headers); if (PEAR::isError($headerElements)) { $this->_smtp->rset(); return $headerElements; } list($from, $textHeaders) = $headerElements; /* Since few MTAs are going to allow this header to be forged * unless it's in the MAIL FROM: exchange, we'll use * Return-Path instead of From: if it's set. */ if (!empty($headers['Return-Path'])) { $from = $headers['Return-Path']; } if (!isset($from)) { $this->_smtp->rset(); return PEAR::raiseError('No From: address has been provided', PEAR_MAIL_SMTP_ERROR_FROM); } $args['verp'] = $this->verp; if (PEAR::isError($res = $this->_smtp->mailFrom($from, $args))) { $error = $this->_error("Failed to set sender: $from", $res); $this->_smtp->rset(); return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_SENDER); } $recipients = $this->parseRecipients($recipients); if (PEAR::isError($recipients)) { $this->_smtp->rset(); return $recipients; } foreach ($recipients as $recipient) { if (PEAR::isError($res = $this->_smtp->rcptTo($recipient))) { $error = $this->_error("Failed to add recipient: $recipient", $res); $this->_smtp->rset(); return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_RECIPIENT); } } /* Send the message's headers and the body as SMTP data. */ if (PEAR::isError($res = $this->_smtp->data($textHeaders . "\r\n\r\n" . $body))) { $error = $this->_error('Failed to send data', $res); $this->_smtp->rset(); return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_DATA); } /* If persistent connections are disabled, destroy our SMTP object. */ if ($this->persist === false) { $this->disconnect(); } return true; } /** * Disconnect and destroy the current SMTP connection. * * @return boolean True if the SMTP connection no longer exists. * * @since 1.1.9 * @access public */ function disconnect() { /* If we have an SMTP object, disconnect and destroy it. */ if (is_object($this->_smtp) && $this->_smtp->disconnect()) { $this->_smtp = null; } /* We are disconnected if we no longer have an SMTP object. */ return ($this->_smtp === null); } /** * Build a standardized string describing the current SMTP error. * * @param string $text Custom string describing the error context. * @param object $error Reference to the current PEAR_Error object. * * @return string A string describing the current SMTP error. * * @since 1.1.7 * @access private */ function _error($text, &$error) { /* Split the SMTP response into a code and a response string. */ list($code, $response) = $this->_smtp->getResponse(); /* Build our standardized error string. */ $msg = $text; $msg .= ' [sMTP: ' . $error->getMessage(); $msg .= " (code: $code, response: $response)]"; return $msg; } } config.inc.php <?php # Script 16.3 - config.inc.php /* This script: * - define constants and settings * - dictates how errors are handled * - defines useful functions */ // Document who created this site, when,why, etc. // ********************************** // // ************ SETTINGS ************ // // Flag variable for site status: define('LIVE', FALSE); // Admin contact address: define('EMAIL', 'my_username_at_google_goes_here@gmail.com'); // Site URL (base for all redirections): define ('BASE_URL','http://www.example.com'); // Location of the MySQL connection script: define ('MYSQL','H:\wamp\www\a3/mysqli_connect.php'); // Adjust the time zone for PHP 5.1 and greater: date_default_timezone_set ('US/Eastern'); // ************ SETTINGS ************ // // ********************************** // //******************************************// // ************ ERROR MANAGEMENT************ // // Create the error handler: function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) { // Build the error message. $message = "<p>An error occurred in script '$e_file' on line $e_line: $e_message\n<br />"; // Add the date and time: $message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />"; // Append $e_vars to the $message: $message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n</p>"; if (!LIVE) { // Development (print the error). echo '<div id="Error">' . $message .'</div><br />'; } else { // Don't show the error: // Send an email to the admin: mail(EMAIL, 'Site Error!', $message,'From: my_username_at_google_goes_here'); // Only print an error message if the error isn't a notice: if ($e_number != E_NOTICE) { echo '<div id="Error">A system error occurred. We apologize for the inconvenience.</div><br />'; } } // End of !LIVE IF. } // End of my_error_handler() definition. // Use my error handler. set_error_handler ('my_error_handler'); // ************ ERROR MANAGEMENT************ // // ****************************************** // ini_set('SMTP', 'smtp.gmail.com'); // SMTP of your provider (same as in Outlook) ini_set('sendmail_from', 'my_username_at_google_goes_here@gmail.com'); // Your emailaddress ?> register.php <?php # Script 16.6 - register.php // This is the registration page for the site. require_once ('includes/config.inc.php'); $page_title = 'Register'; include ('includes/header.html'); if (isset($_POST['submitted'])) { // Handle the form. require_once (MYSQL); // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $fn = $ln = $e = $p = FALSE; // Check for a first name: if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) { $fn = mysqli_real_escape_string ($dbc, $trimmed['first_name']); } else { echo '<p class="error">Please enter your first name!</p>'; } // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Please enter your last name!</p>'; } // Check for an email address: if (preg_match ('/^[\w.-]+@[\w.-]+\.[AZa-z]{2,6}$/', $trimmed['email'])) { $e = mysqli_real_escape_string ($dbc, $trimmed['email']); } else { echo '<p class="error">Please enter a valid email address!</p>'; } // Check for a password and match against the confirmed password: if (preg_match ('/^\w{4,20}$/', $trimmed['password1']) ) { if ($trimmed['password1'] == $trimmed['password2']) { $p = mysqli_real_escape_string ($dbc, $trimmed['password1']); } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { echo '<p class="error">Please enter a valid password!</p>'; } if ($fn && $ln && $e && $p) { // If everything's OK... // Make sure the email address is available: $q = "SELECT user_id FROM users WHERE email='$e'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQLError: " . mysqli_error($dbc)); if (mysqli_num_rows($r) == 0) { //Available. // Create the activation code: $a = md5(uniqid(rand(), true)); // Add the user to the database: $q = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', SHA1('$p'), '$fn', '$ln', '$a', NOW() )"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Send the email: $body = "Thank you for registering at <whatever site>. To activate your account, please click on this link:\n\n"; $body .= BASE_URL . 'activate.php? x=' . urlencode($e) . "&y=$a"; mail($trimmed['email'], 'Registration Confirmation', $body, 'From: my_username_at_google_goes_here@gmail.com'); // Finish the page: echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>'; include ('includes/footer.html'); // Include the HTML footer. exit(); // Stop the page. } else { // If it did not run OK. echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; } } else { // The email address is not available. echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>'; } } else { // If one of the data tests failed. echo '<p class="error">Please re-enter your passwords and try again.</p>'; } mysqli_close($dbc); } // End of the main Submit conditional. ?> <h1>Register</h1> <form action="register.php" method="post"> <fieldset> <p><b>First Name:</b> <input type="text" name="first_name" size="20" maxlength= "20" value="<?php if (isset($trimmed ['first_name'])) echo $trimmed ['first_name']; ?>" /></p> <p><b>Last Name:</b> <input type="text" name="last_name" size="20" maxlength= "40" value="<?php if (isset($trimmed ['last_name'])) echo $trimmed ['last_name']; ?>" /></p> <p><b>Email Address:</b> <input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" /> </p> <p><b>Password:</b> <input type= "password" name="password1" size="20" maxlength="20" /> <small>Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.</small></p> <p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Register" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php // Include the HTML footer. include ('includes/footer.html'); ?>
  8. Well, I am a php beginner trying to develop a php form which uses the confirmation email process as a validation technique. I tried editing php.ini, downloaded pear, tried different servers but everytime I end with having an error sending the confirmation email. I used Yahoo, Google, & AOL servers. I will explain the google trial as I tested sending an email using Outlook Express using these settings & it was a successful trial. Server details Name: Google SMTP Server: smtp.google.com Port: 465 php.ini Configuration [mail function] For Win32 only. SMTP = smtp.google.com smtp_port = 465 Pear Settings smtp.php <?php /** Error: Failed to create a Net_SMTP object */ define('PEAR_MAIL_SMTP_ERROR_CREATE', 10000); /** Error: Failed to connect to SMTP server */ define('PEAR_MAIL_SMTP_ERROR_CONNECT', 10001); /** Error: SMTP authentication failure */ define('PEAR_MAIL_SMTP_ERROR_AUTH', 10002); /** Error: No From: address has been provided */ define('PEAR_MAIL_SMTP_ERROR_FROM', 10003); /** Error: Failed to set sender */ define('PEAR_MAIL_SMTP_ERROR_SENDER', 10004); /** Error: Failed to add recipient */ define('PEAR_MAIL_SMTP_ERROR_RECIPIENT', 10005); /** Error: Failed to send data */ define('PEAR_MAIL_SMTP_ERROR_DATA', 10006); /** * SMTP implementation of the PEAR Mail interface. Requires the Net_SMTP class. * @access public * @package Mail * @version $Revision: 1.28 $ */ class Mail_smtp extends Mail { /** * SMTP connection object. * * @var object * @access private */ var $_smtp = null; /** * The SMTP host to connect to. * @var string */ var $host = 'smtp.gmail.com'; /** * The port the SMTP server is on. * @var integer */ var $port = 465; /** * Should SMTP authentication be used? * * This value may be set to true, false or the name of a specific * authentication method. * * If the value is set to true, the Net_SMTP package will attempt to use * the best authentication method advertised by the remote SMTP server. * * @var mixed */ var $auth = true; /** * The username to use if the SMTP server requires authentication. * @var string */ var $username = 'my_username_at_google_goes_here'; /** * The password to use if the SMTP server requires authentication. * @var string */ var $password = 'my_password'; /** * Hostname or domain that will be sent to the remote SMTP server in the * HELO / EHLO message. * * @var string */ var $localhost = 'smtp.gmail.com'; /** * SMTP connection timeout value. NULL indicates no timeout. * * @var integer */ var $timeout = null; /** * Whether to use VERP or not. If not a boolean, the string value * will be used as the VERP separators. * * @var mixed boolean or string */ var $verp = false; /** * Turn on Net_SMTP debugging? * * @var boolean $debug */ var $debug = false; /** * Indicates whether or not the SMTP connection should persist over * multiple calls to the send() method. * * @var boolean */ var $persist = false; /** * Constructor. * * Instantiates a new Mail_smtp:: object based on the parameters * passed in. It looks for the following parameters: * host The server to connect to. Defaults to localhost. * port The port to connect to. Defaults to 25. * auth SMTP authentication. Defaults to none. * username The username to use for SMTP auth. No default. * password The password to use for SMTP auth. No default. * localhost The local hostname / domain. Defaults to localhost. * timeout The SMTP connection timeout. Defaults to none. * verp Whether to use VERP or not. Defaults to false. * debug Activate SMTP debug mode? Defaults to false. * persist Should the SMTP connection persist? * * If a parameter is present in the $params array, it replaces the * default. * * @param array Hash containing any parameters different from the * defaults. * @access public */ function Mail_smtp($params) { if (isset($params['smtp.gmail.com'])) $this->host = $params['smtp.gmail.com']; if (isset($params['465'])) $this->port = $params['465']; if (isset($params['true'])) $this->auth = $params['true']; if (isset($params['my_username_at_google_goes_here'])) $this->username = $params['my_username_at_google_goes_here']; if (isset($params['my_password'])) $this->password = $params['my_password']; if (isset($params['smtp.gmail.com'])) $this->localhost = $params['smtp.gmail.com']; if (isset($params['timeout'])) $this->timeout = $params['timeout']; if (isset($params['verp'])) $this->verp = $params['verp']; if (isset($params['debug'])) $this->debug = (boolean)$params['debug']; if (isset($params['persist'])) $this->persist = (boolean)$params['persist']; register_shutdown_function(array(&$this, '_Mail_smtp')); } /** * Destructor implementation to ensure that we disconnect from any * potentially-alive persistent SMTP connections. */ function _Mail_smtp() { $this->disconnect(); } /** * Implements Mail::send() function using SMTP. * * @param mixed $recipients Either a comma-seperated list of recipients * (RFC822 compliant), or an array of recipients, * each RFC822 valid. This may contain recipients not * specified in the headers, for Bcc:, resending * messages, etc. * * @param array $headers The array of headers to send with the mail, in an * associative array, where the array key is the * header name (e.g., 'Subject'), and the array value * is the header value (e.g., 'test'). The header * produced from those values would be 'Subject: * test'. * * @param string $body The full text of the message body, including any * Mime parts, etc. * * @return mixed Returns true on success, or a PEAR_Error * containing a descriptive error message on * failure. * @access public */ function send($recipients, $headers, $body) { include_once 'Net/SMTP.php'; /* If we don't already have an SMTP object, create one. */ if (is_object($this->_smtp) === false) { $this->_smtp =& new Net_SMTP($this->host, $this->port, $this->localhost); /* If we still don't have an SMTP object at this point, fail. */ if (is_object($this->_smtp) === false) { return PEAR::raiseError('Failed to create a Net_SMTP object', PEAR_MAIL_SMTP_ERROR_CREATE); } /* Configure the SMTP connection. */ if ($this->debug) { $this->_smtp->setDebug(true); } /* Attempt to connect to the configured SMTP server. */ if (PEAR::isError($res = $this->_smtp->connect($this->timeout))) { $error = $this->_error('Failed to connect to ' . $this->host . ':' . $this->port, $res); return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_CONNECT); } /* Attempt to authenticate if authentication has been enabled. */ if ($this->auth) { $method = is_string($this->auth) ? $this->auth : ''; if (PEAR::isError($res = $this->_smtp->auth($this->username, $this->password, $method))) { $error = $this->_error("$method authentication failure", $res); $this->_smtp->rset(); return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_AUTH); } } } $this->_sanitizeHeaders($headers); $headerElements = $this->prepareHeaders($headers); if (PEAR::isError($headerElements)) { $this->_smtp->rset(); return $headerElements; } list($from, $textHeaders) = $headerElements; /* Since few MTAs are going to allow this header to be forged * unless it's in the MAIL FROM: exchange, we'll use * Return-Path instead of From: if it's set. */ if (!empty($headers['Return-Path'])) { $from = $headers['Return-Path']; } if (!isset($from)) { $this->_smtp->rset(); return PEAR::raiseError('No From: address has been provided', PEAR_MAIL_SMTP_ERROR_FROM); } $args['verp'] = $this->verp; if (PEAR::isError($res = $this->_smtp->mailFrom($from, $args))) { $error = $this->_error("Failed to set sender: $from", $res); $this->_smtp->rset(); return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_SENDER); } $recipients = $this->parseRecipients($recipients); if (PEAR::isError($recipients)) { $this->_smtp->rset(); return $recipients; } foreach ($recipients as $recipient) { if (PEAR::isError($res = $this->_smtp->rcptTo($recipient))) { $error = $this->_error("Failed to add recipient: $recipient", $res); $this->_smtp->rset(); return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_RECIPIENT); } } /* Send the message's headers and the body as SMTP data. */ if (PEAR::isError($res = $this->_smtp->data($textHeaders . "\r\n\r\n" . $body))) { $error = $this->_error('Failed to send data', $res); $this->_smtp->rset(); return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_DATA); } /* If persistent connections are disabled, destroy our SMTP object. */ if ($this->persist === false) { $this->disconnect(); } return true; } /** * Disconnect and destroy the current SMTP connection. * * @return boolean True if the SMTP connection no longer exists. * * @since 1.1.9 * @access public */ function disconnect() { /* If we have an SMTP object, disconnect and destroy it. */ if (is_object($this->_smtp) && $this->_smtp->disconnect()) { $this->_smtp = null; } /* We are disconnected if we no longer have an SMTP object. */ return ($this->_smtp === null); } /** * Build a standardized string describing the current SMTP error. * * @param string $text Custom string describing the error context. * @param object $error Reference to the current PEAR_Error object. * * @return string A string describing the current SMTP error. * * @since 1.1.7 * @access private */ function _error($text, &$error) { /* Split the SMTP response into a code and a response string. */ list($code, $response) = $this->_smtp->getResponse(); /* Build our standardized error string. */ $msg = $text; $msg .= ' [sMTP: ' . $error->getMessage(); $msg .= " (code: $code, response: $response)]"; return $msg; } } A Form Configuration File config.inc.php <?php # Script 16.3 - config.inc.php /* This script: * - define constants and settings * - dictates how errors are handled * - defines useful functions */ // Document who created this site, when,why, etc. // ********************************** // // ************ SETTINGS ************ // // Flag variable for site status: define('LIVE', FALSE); // Admin contact address: define('EMAIL', 'my_username_at_google_goes_here@gmail.com'); // Site URL (base for all redirections): define ('BASE_URL','http://www.example.com'); // Location of the MySQL connection script: define ('MYSQL','H:\wamp\www\a3/mysqli_connect.php'); // Adjust the time zone for PHP 5.1 and greater: date_default_timezone_set ('US/Eastern'); // ************ SETTINGS ************ // // ********************************** // //******************************************// // ************ ERROR MANAGEMENT************ // // Create the error handler: function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) { // Build the error message. $message = "<p>An error occurred in script '$e_file' on line $e_line: $e_message\n<br />"; // Add the date and time: $message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />"; // Append $e_vars to the $message: $message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n</p>"; if (!LIVE) { // Development (print the error). echo '<div id="Error">' . $message .'</div><br />'; } else { // Don't show the error: // Send an email to the admin: mail(EMAIL, 'Site Error!', $message,'From: my_username_at_google_goes_here'); // Only print an error message if the error isn't a notice: if ($e_number != E_NOTICE) { echo '<div id="Error">A system error occurred. We apologize for the inconvenience.</div><br />'; } } // End of !LIVE IF. } // End of my_error_handler() definition. // Use my error handler. set_error_handler ('my_error_handler'); // ************ ERROR MANAGEMENT************ // // ****************************************** // ini_set('SMTP', 'smtp.gmail.com'); // SMTP of your provider (same as in Outlook) ini_set('sendmail_from', 'my_username_at_google_goes_here@gmail.com'); // Your emailaddress ?> register.php <?php # Script 16.6 - register.php // This is the registration page for the site. require_once ('includes/config.inc.php'); $page_title = 'Register'; include ('includes/header.html'); if (isset($_POST['submitted'])) { // Handle the form. require_once (MYSQL); // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $fn = $ln = $e = $p = FALSE; // Check for a first name: if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) { $fn = mysqli_real_escape_string ($dbc, $trimmed['first_name']); } else { echo '<p class="error">Please enter your first name!</p>'; } // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Please enter your last name!</p>'; } // Check for an email address: if (preg_match ('/^[\w.-]+@[\w.-]+\.[AZa-z]{2,6}$/', $trimmed['email'])) { $e = mysqli_real_escape_string ($dbc, $trimmed['email']); } else { echo '<p class="error">Please enter a valid email address!</p>'; } // Check for a password and match against the confirmed password: if (preg_match ('/^\w{4,20}$/', $trimmed['password1']) ) { if ($trimmed['password1'] == $trimmed['password2']) { $p = mysqli_real_escape_string ($dbc, $trimmed['password1']); } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { echo '<p class="error">Please enter a valid password!</p>'; } if ($fn && $ln && $e && $p) { // If everything's OK... // Make sure the email address is available: $q = "SELECT user_id FROM users WHERE email='$e'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQLError: " . mysqli_error($dbc)); if (mysqli_num_rows($r) == 0) { //Available. // Create the activation code: $a = md5(uniqid(rand(), true)); // Add the user to the database: $q = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', SHA1('$p'), '$fn', '$ln', '$a', NOW() )"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Send the email: $body = "Thank you for registering at <whatever site>. To activate your account, please click on this link:\n\n"; $body .= BASE_URL . 'activate.php? x=' . urlencode($e) . "&y=$a"; mail($trimmed['email'], 'Registration Confirmation', $body, 'From: my_username_at_google_goes_here@gmail.com'); // Finish the page: echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>'; include ('includes/footer.html'); // Include the HTML footer. exit(); // Stop the page. } else { // If it did not run OK. echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; } } else { // The email address is not available. echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>'; } } else { // If one of the data tests failed. echo '<p class="error">Please re-enter your passwords and try again.</p>'; } mysqli_close($dbc); } // End of the main Submit conditional. ?> <h1>Register</h1> <form action="register.php" method="post"> <fieldset> <p><b>First Name:</b> <input type="text" name="first_name" size="20" maxlength= "20" value="<?php if (isset($trimmed ['first_name'])) echo $trimmed ['first_name']; ?>" /></p> <p><b>Last Name:</b> <input type="text" name="last_name" size="20" maxlength= "40" value="<?php if (isset($trimmed ['last_name'])) echo $trimmed ['last_name']; ?>" /></p> <p><b>Email Address:</b> <input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" /> </p> <p><b>Password:</b> <input type= "password" name="password1" size="20" maxlength="20" /> <small>Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.</small></p> <p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Register" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php // Include the HTML footer. include ('includes/footer.html'); ?> <<<<<THE ERROR MESSAGE>>>>>> 1. Fatal error: Maximum execution time of 30 seconds exceeded in E:\wamp\www\a3\htdocs\includes\config.inc.php on line 37. Actually, it took about 10 minutes before displaying this message. I have spent 2 weeks trying to fix this but I couldn't go any further. Do you have any ideas ?!
×
×
  • 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.