Ilovetopk Posted March 16, 2010 Share Posted March 16, 2010 I'm working on a form for my website where you enter your login name, and it resets your password, and sends it to the email address you singed up with. I can't seem to make it work. Can anyone give me suggestions/point out problems in my script? the weird thing is, I can get it to send the information to the php script, but it just shows a blank page after I hit submit. Is it a simple problem? NOTE: I've been coding php for a very short time, I've got a lot of the basics down, but i might have missed something. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Password Recovery</title> </head><body> <form name="recover" id="recover" method="post" action="password-forgot.php"> Login name: <input name="user" class="textfield" id="user" type="text" /> <input type="submit" name="Submit" value="Recover" /> </form> </body></html> <?php //password-forgot.php //enters connection details require_once('config.php'); //connects to mysql database $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //selects database $db = mysql_select_db(DB_DATABASE, $link); if(!$db) { die("Unable to select database"); } //cleans posted login name $login = clean($_POST['user']); //gets email from server $query="SELECT email FROM members WHERE login=$login"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } $row = mysql_fetch_array($result) //sets $email as their emqail address $email = $row['email'] //generates random password function createRandomPassword() { $chars = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 7) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } //defines random password as variable $password = createRandomPassword(); //updates password on database $query="UPDATE members SET passwd=(md5['$password']) WHERE login=$login"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } //sends password to email address $to = "$email"; $subject = "Password recovery"; $message = "Your randomly generated password on Ilovetopk.is-a-geek.com for user $login is $password. Login in and change your password as soon as possible. If you did not want to reset your password, please inform me and change it back to normal. Please do not respond to this email."; $from = "me@mysite.com"; $headers = "From: $from"; $mail=mail($to,$subject,$message,$headers); //redirects or tells of failure if($mail) { header("location: password-sent.php"); exit(); } else { die("Query failed. Contact the website administratior to solve this problem."); } //unset database unset($db); ?> Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/ Share on other sites More sharing options...
fr34k Posted March 16, 2010 Share Posted March 16, 2010 I'm working on a form for my website where you enter your login name, and it resets your password, and sends it to the email address you singed up with. I can't seem to make it work. Can anyone give me suggestions/point out problems in my script? the weird thing is, I can get it to send the information to the php script, but it just shows a blank page after I hit submit. Is it a simple problem? NOTE: I've been coding php for a very short time, I've got a lot of the basics down, but i might have missed something. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Password Recovery</title> </head><body> <form name="recover" id="recover" method="post" action="password-forgot.php"> Login name: <input name="user" class="textfield" id="user" type="text" /> <input type="submit" name="Submit" value="Recover" /> </form> </body></html> <?php //password-forgot.php //enters connection details require_once('config.php'); //connects to mysql database $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //selects database $db = mysql_select_db(DB_DATABASE, $link); if(!$db) { die("Unable to select database"); } //cleans posted login name $login = clean($_POST['user']); //gets email from server $query="SELECT email FROM members WHERE login=$login"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } $row = mysql_fetch_array($result) //sets $email as their emqail address $email = $row['email'] //generates random password function createRandomPassword() { $chars = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 7) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } //defines random password as variable $password = createRandomPassword(); //updates password on database $query="UPDATE members SET passwd=(md5['$password']) WHERE login=$login"; $result=mysql_query($query); if(!$result) { print("Query Error: ".mysql_error()); } //sends password to email address $to = "$email"; $subject = "Password recovery"; $message = "Your randomly generated password on Ilovetopk.is-a-geek.com for user $login is $password. Login in and change your password as soon as possible. If you did not want to reset your password, please inform me and change it back to normal. Please do not respond to this email."; $from = "me@mysite.com"; $headers = "From: $from"; $mail=mail($to,$subject,$message,$headers); //redirects or tells of failure if($mail) { header("location: password-sent.php"); exit(); } else { die("Query failed. Contact the website administratior to solve this problem."); } //unset database unset($db); ?> Just glancing over your code, you're missing some semicolons. Ex: $row = mysql_fetch_array($result) $email = $row['email'] Those two lines should end in semicolons. Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027259 Share on other sites More sharing options...
Ilovetopk Posted March 16, 2010 Author Share Posted March 16, 2010 fixed it, same thing is happening.... P.S. If you want to see whats happening, click here, use whats in the box as the user, it's in the database. also, I know php is working because my wordpress blog on the same server works fine. Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027267 Share on other sites More sharing options...
fr34k Posted March 16, 2010 Share Posted March 16, 2010 fixed it, same thing is happening.... P.S. If you want to see whats happening, click here, use whats in the box as the user, it's in the database. also, I know php is working because my wordpress blog on the same server works fine. 1) Can you verify that there are no similar syntax errors in "config.php?" 2) Also, can you access your web server's logs to see if PHP is throwing any errors? Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027273 Share on other sites More sharing options...
Psycho Posted March 16, 2010 Share Posted March 16, 2010 fixed it, same thing is happening.... P.S. If you want to see whats happening, click here, use whats in the box as the user, it's in the database. also, I know php is working because my wordpress blog on the same server works fine. I hope you realize that that page isn't blank!!! Check the source code for the page returned and you will see the PHP code. There is a serious problem here. Either the PHP is not getting processed or you are outputting the PHP. Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027278 Share on other sites More sharing options...
Ilovetopk Posted March 16, 2010 Author Share Posted March 16, 2010 1) Can you verify that there are no similar syntax errors in "config.php?" 2) Also, can you access your web server's logs to see if PHP is throwing any errors? I use config.php for all of my pages that connect to the database. It just defines DB_host etc. as my host etc. It's fine. I'm a total noob at this, how would i access my logs to check for php errors? I'm sure I can, as I'm running it off my home computer. Server:apache Also, i know the php isn't blank, I've looked in the sourece code, it's all their, it's just not doing anything. Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027281 Share on other sites More sharing options...
fr34k Posted March 16, 2010 Share Posted March 16, 2010 I hope you realize that that page isn't blank!!! Check the source code for the page returned and you will see the PHP code. There is a serious problem here. Either the PHP is not getting processed or you are outputting the PHP. Funny thing, Chrome displays a blank page when viewing the source. Firefox actually does display the PHP source that's outputted. Also, i know the php isn't blank, I've looked in the sourece code, it's all their, it's just not doing anything. Your PHP code isn't being parsed by the server. It's going straight through. You can verify this by pasting this link into your address bar (as long as it isn't Chrome:) view-source:http://ilovetopk.is-a-geek.com/PHP-Login/password-forgot.php Your error log for Apache is likely to be located in: /var/log/apache/error.log or /var/log/apache2/error.log Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027287 Share on other sites More sharing options...
Ilovetopk Posted March 16, 2010 Author Share Posted March 16, 2010 I hope you realize that that page isn't blank!!! Check the source code for the page returned and you will see the PHP code. There is a serious problem here. Either the PHP is not getting processed or you are outputting the PHP. Funny thing, Chrome displays a blank page when viewing the source. Firefox actually does display the PHP source that's outputted. Also, i know the php isn't blank, I've looked in the sourece code, it's all their, it's just not doing anything. Your PHP code isn't being parsed by the server. It's going straight through. You can verify this by pasting this link into your address bar (as long as it isn't Chrome:) view-source:http://ilovetopk.is-a-geek.com/PHP-Login/password-forgot.php Your error log for Apache is likely to be located in: /var/log/apache/error.log or /var/log/apache2/error.log here are all the errors from today, but their stuff like it can't find a favicon, and i blocked people from seeing my directories, nothing about php. [Tue Mar 16 08:51:47 2010] [error] [client 209.7.238.43] script 'E:/xampplite/htdocs/PHP-Login/forgot.php' not found or unable to stat [Tue Mar 16 08:51:56 2010] [error] [client 209.7.238.43] File does not exist: E:/xampplite/htdocs/PHP-Login/forgot-password [Tue Mar 16 08:51:58 2010] [error] [client 209.7.238.43] script 'E:/xampplite/htdocs/PHP-Login/forgot-password.php' not found or unable to stat [Tue Mar 16 08:52:09 2010] [error] [client 209.7.238.43] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:06:15 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:06:19 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:06:24 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:09:11 2010] [error] [client 67.77.212.11] Directory index forbidden by Options directive: E:/xampplite/htdocs/PHP-Login/ [Tue Mar 16 16:09:11 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:09:18 2010] [error] [client 67.77.212.11] script 'E:/xampplite/htdocs/PHP-Login/index.php' not found or unable to stat [Tue Mar 16 16:09:19 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:09:44 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:09:45 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:09:46 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:09:52 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:09:58 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:10:00 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:10:03 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:10:05 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:14:15 2010] [error] [client 72.128.10.117] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:14:15 2010] [error] [client 72.128.10.117] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:15:28 2010] [error] [client 160.109.98.44] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:19:39 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:19:41 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:19:45 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:23:16 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:23:19 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:25:57 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:25:59 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:26:03 2010] [error] [client 67.77.212.11] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:33:25 2010] [error] [client 75.89.235.97] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:33:28 2010] [error] [client 75.89.235.97] File does not exist: E:/xampplite/htdocs/favicon.ico [Tue Mar 16 16:33:32 2010] [error] [client 75.89.235.97] Directory index forbidden by Options directive: E:/xampplite/htdocs/PHP-Login/ Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027299 Share on other sites More sharing options...
Psycho Posted March 16, 2010 Share Posted March 16, 2010 You aren't going to have any PHP errors for that page because the PHP code isn't being processed! Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027305 Share on other sites More sharing options...
Ilovetopk Posted March 16, 2010 Author Share Posted March 16, 2010 You aren't going to have any PHP errors for that page because the PHP code isn't being processed! ok, gimme some suggestions! My wordpress blog (in a diffrent directory) is almost entirely php, and it's working! Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027308 Share on other sites More sharing options...
Psycho Posted March 16, 2010 Share Posted March 16, 2010 Is the 2nd code block you posted in your first post the content for the "password-forgot.php" page or is it a separate file that is included? If so, it could be a problem in how you are including it. Try create a simple "Hello world" script in that directory and test it. Hello <?php echo "World!"; ?> What does that produce? Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027312 Share on other sites More sharing options...
Ilovetopk Posted March 16, 2010 Author Share Posted March 16, 2010 Is the 2nd code block you posted in your first post the content for the "password-forgot.php" page or is it a separate file that is included? If so, it could be a problem in how you are including it. Try create a simple "Hello world" script in that directory and test it. Hello <?php echo "World!"; ?> What does that produce? suddenly something happened World!Query Error: Unknown column 'test' in 'where clause' Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in E:\xampplite\htdocs\PHP-Login\forgot.php on line 27 Query Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '['']) WHERE login=test' at line 1 Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in E:\xampplite\htdocs\PHP-Login\forgot.php on line 67 Could not mail password, try again in a few minutes, or contact the admin. any idea how to fix all of this? Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027332 Share on other sites More sharing options...
Ilovetopk Posted March 16, 2010 Author Share Posted March 16, 2010 ok, i got the errors down to here. Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in E:\xampplite\htdocs\PHP-Login\forgot.php on line 66 Could not mail password, try again in a few minutes, or contact the admin. The "Could not mail password, try again in a few minutes, or contact the admin." is my error if i can't send the email, so i just need to work out the sendmail function Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027340 Share on other sites More sharing options...
Psycho Posted March 16, 2010 Share Posted March 16, 2010 ok, i got the errors down to here. Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in E:\xampplite\htdocs\PHP-Login\forgot.php on line 66 Could not mail password, try again in a few minutes, or contact the admin. The "Could not mail password, try again in a few minutes, or contact the admin." is my error if i can't send the email, so i just need to work out the sendmail function The error is pretty self explanatory. The PHP.ini file has localhost configured as the mail server and there isn't one. You need to have a mail server available in order to send email. Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027349 Share on other sites More sharing options...
Ilovetopk Posted March 16, 2010 Author Share Posted March 16, 2010 The error is pretty self explanatory. The PHP.ini file has localhost configured as the mail server and there isn't one. You need to have a mail server available in order to send email. ok, any suggestions on an easy to set up mail server. I was looking at mercury mail, but i need a good tutorial on how to set it up. Quote Link to comment https://forums.phpfreaks.com/topic/195487-help-with-password-recovery-script/#findComment-1027352 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.