Password Variable Not Echoing When Emailed

Hello guys,

I have a PHP form where when you submit, this PHP code processes it so that it’ll show the user’s info with a random password. I was having a hard time how I can echo this password variable when emailed to me. But it was echoing on the browser. I know this isn’t safe showing the password on the browser but it’s an assignment. Can someone help?

[php]<?php

#We used the superglobal $_GET here
if (!($_GET[‘firstname’] && $_GET[‘lastname’] && $_GET[‘email’]
&& $_GET[‘email’] && $_GET[‘username’])) {

#with the header() function, no output can come before it.
#echo “Please make sure you’ve filled in all required information.”;

$query_string = $_SERVER[‘QUERY_STRING’];
#add a flag called “error” to tell contact_form.php that something needs fixed
$url = “http://”.$_SERVER[‘HTTP_HOST’]."/project/lab10_Obj01/registration_form.php?".$query_string."&error=1";
header("Location: ".$url);
exit();

}

extract($_GET, EXTR_PREFIX_SAME, “get”);

#construct email message
$email_message = "Name: “.$firstname.” “.$lastname.”
Email: “.$email.”
Uername: “.$username.”
Password: “.$password.”
User Agent: “.$_SERVER[‘HTTP_USER_AGENT’].”
IP Address: ".$_SERVER[‘REMOTE_ADDR’];

#construct the email headers
$to = “some email here”;
$from = $_GET[‘email’];
$email_subject = “Registration Details”;

#now mail
mail($to, $email_subject, $email_message, "From: ".$from);

echo “Thank you “.$firstname.” “.$lastname.”! You are now registered.

”;
echo “Here’s your registration information:

”;

echo “Email: “.$email.”
”;
echo “Username: “.$username.”
”;
$string = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”;
$password = substr(str_shuffle(“string”),0,8); // assigns random password from string variable up to 8 characters
echo “Password: “.$password.”
”;

echo "You are currently working on ".$_SERVER[‘HTTP_USER_AGENT’];
echo "
The IP address of the computer you’re working on is ".$_SERVER[‘HTTP_X_FORWARDED_FOR’];

?>[/php]

I got it to work! Ugh… lol

Sponsor our Newsletter | Privacy Policy | Terms of Service