Jump to content


Photo

*SOLVED* Lost password


  • Please log in to reply
5 replies to this topic

#1 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 30 April 2006 - 08:46 PM

I'm trying to make work a script from this site's (members) tutorials ...http://www.phpfreaks.com/tutorials/40/8.php to learn how the mail function works but i keep getting 2 errors
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Notice: Undefined variable: pass in c:\foreign\easyphp1-8\www\agence\test\pasoub.php on line 48

Warning: 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 c:\foreign\easyphp1-8\www\agence\test\pasoub.php on line 74
Your password has been sent! Please check your email![/quote]

Finally the 2 files:

PasOub.html
<html>
    <form  method="post" action="PasOub.php">
        <table width="50%" border="0" cellspacing="0" cellpadding="4">
            <tr><td>Please enter your email address</td>
            <td><input name="email" type="text"></td></tr>

            <tr><td>&nbsp;</td>
            <td><input name="recover" type="hidden" value="recover">
            <input type="submit" name="Submit" value="Recover My Password!"></td></tr>
        </table>
    </form>
</html>


PasOub.php
<?
session_start();

$email  = $HTTP_POST_VARS['email'];

$host = "???;
$user = "???";
$pass = "???";
$base = "???";

$db_conx = mysql_connect($host,$user,$pass) or print("erreur de connection mysql");
mysql_select_db($base, $db_conx) or print("erreur connection base");

switch($_POST['recover']){
default:
include 'PasOub.html';
break;

case "recover":
recover_pw($_POST['email']);
break;
}
function recover_pw($email){
if(!$email){
echo "You forgot to enter your Email address
<strong>Knucklehead</strong><br />";
include 'PasOub.html';
exit();
}
// quick check to see if record exists
$sql_check = mysql_query("SELECT * FROM user WHERE email='$email'");
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
echo "No records found matching your email address<br />";
include 'PasOub.html';
exit();
}

// Everything looks ok, generate password, update it and send it!

function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}

$random_password = makeRandomPassword();

#$db_password = md5($random_password);

#$sql = mysql_query("UPDATE user SET password='$password'
#WHERE email='$email'");

$subject = "Your Password at MyWebsite!";
$message = "Hi, we have reset your password.

New Password: $random_password

http://www.mywebsite.com/login.php

Thanks!
The Webmaster

This is an automated response, please do not reply!";

mail($email, $subject, $message, "From: MyDomain Webmaster<admin@mydomain.com>\n
X-Mailer: PHP/" . phpversion());
echo "Your password has been sent! Please check your email!<br />";
}
?>


Of course the mail is not sent and i spent aloooot of time working out diffrent things ...
i'm using php 4.3. on windows and i added the line smtp_port=25 at the php.ini do i need to add anything else ? why it doesn't understand $pass ?

Christos


#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 May 2006 - 12:37 AM

first of all, it really helps when you put a little note in the code you post which line is for instance, 48, as described in your error message. just so you know.

as to your first error:

Notice: Undefined variable: pass in c:\foreign\easyphp1-8\www\agence\test\pasoub.php on line 48

$pass = $pass . $tmp;

is your problem. you have not set $pass to anything and now you are trying to add $tmp to it. you will need to initialize it before the while loop before you can add stuff to it.

2nd:

#$sql = mysql_query("UPDATE user SET password='$password'
#WHERE email='$email'");

even though you didn't mention this, i thought i should point out that you are setting password to $password which doesn't exist. i think you probably meant

#$sql = mysql_query("UPDATE user SET password='$random_password'
#WHERE email='$email'");


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 May 2006 - 10:12 AM

The main reason why your're geting the following error message:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: 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 c:\foreign\easyphp1-8\www\agence\test\pasoub.php on line 74[/quote]is becuase your havn't setup PHP to use an SMTP Server. PHP needs to be pointed to an SMTP server in order to send the emails, with out an SMTP server your emails are going no where!

To setup up PHP to use an SMTP server you'll need to edit your php.ini file and find the following line:
SMTP = localhost
Change localhost to the smtp address. The address will be like the following: smtp.hostname.com. Usually you'll find your ISP will have an SMTP server you can use.

Once you have applied the changes save your php.in file and restart Apache

#4 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 01 May 2006 - 01:05 PM

Hmm it's not very clear ...at the tutorial (http://www.phpfreaks...orials/40/8.php)
they don't seem to initialise $pass with something and it still works...for other users :)

So i keep getting this[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Notice: Undefined variable: pass in c:\foreign\easyphp1-8\www\agence\test\pasoub.php on line 48[/quote]

Any other ideas ???


P.S Otherwise the 2 tips about the database and the php.ini -> corrected

Thumbs up !!!

christos

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 May 2006 - 02:50 PM

Others may not get the notice message becuase they may have error reporting turned off or is set not report any notice errors.

Now the reason why you are getting the notice error is becuase when php goes through the while loop for the first time in the makeRandomPassword function the $pass variable doesn't actually exist, until the it loops through the secound time.

To stop php from displaying the message either place the @ symbol in front of $pass like so:
@$pass = $pass . $tmp;
or first create the $pass variable with a blank value before the while loop like so:
$pass = "";
while ($i <= 7) {


#6 christo

christo
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 01 May 2006 - 11:01 PM

It worked even with the pass problem finally but i leant something new too !!!

So problem solved :-)

Thanks

christos




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users