Page 1 of 1

PHP Register/Login Help...

Posted: Sun Sep 21, 2003 11:52 pm
by Tortured911
I've been to script sites for PHP and found some scripts to use for making a login/register thing for people to register and become members of my site that is currently in the making. When I use the scripts it shows a blank page when I'm done...

I'm really new at coding PHP even though I've been installing hacks on forums for a decent amount of time. Does anyone know how to make a register/login thing? I had a friend set up a database to store the info in and even set up the tables for me, yet he doesn't know how to do it neither...so help please? :(

Posted: Mon Sep 22, 2003 12:18 am
by jason
I would start here:
viewtopic.php?t=6521

Posted: Mon Sep 22, 2003 12:39 am
by Tortured911
I looked at that tutorial you wrote and gave it a shot making each page like you said and stuff did show up,

"$_SESSION[username] equals Jason" on each page besides the form page which asks for login name and password...

My question is how do I make it where people can register and my database store that info so they can login with it after they register? I'd like to make a register thing so they can register to be a member, and then a way for them to login with the username and password that they choose. I'm not that bright, so I need even more help. :?

Posted: Mon Sep 22, 2003 3:22 am
by Nay
Make another file called signup.php. Do it something like:

Code: Select all

<?

$sub = $_GET['submit'];

if(isset($sub) && $sub=="yes") {
// encrypt the password
// connect to mysql
// insert the values
// close mysql and redirect to a success page
}

else {

echo <<< END

<form name="signup" method="post" action="$PHP_SELF?submit=yes">
<input type="text" name="username" /><br />
<input type="password" name="password" /><br />
<input type="submit" value="submit">
</form>

END;

}

?>
Hope that helps,

-Nay

Posted: Mon Sep 22, 2003 3:37 am
by Tortured911
I have everything working, but the way its set up, it emails the user to validate the email address...but it's not emailing me when I test it out...

Here's the code:
Code wrote:// Let's mail the user!
$subject = "Your Membership at Virtual Hell!";
$message = "Dear $first_name $last_name,
Thank you for registering!

You are two steps away from logging in and accessing our exclusive members area.

To activate your membership,
please click here: http://www.eustadia.zeroconcept.net/wil ... b_password

Once you activate your membership, you will be able to login
with the following information:
Username: $username
Password: $random_password

Thanks!
The Webmaster

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

mail($email_address, $subject, $message,
"From: Virtual Hell Webmaster<william@eustadia.zeroconcept.net>\n
X-Mailer: PHP/" . phpversion());
echo 'Your membership information has been mailed to your email address!
Please check it and follow the directions!';
}

?>
What do I do? It's not working... :?

Posted: Mon Sep 22, 2003 3:48 am
by Nay

Code: Select all

<?php

$subject = "Your Membership at Virtual Hell!";
$message = "Dear $first_name $last_name,
Thank you for registering!

You are two steps away from logging in and accessing our exclusive members area.

To activate your membership,
please click here: http://www.eustadia.zeroconcept.net/wil ... b_password

Once you activate your membership, you will be able to login
with the following information:
Username: $username
Password: $random_password

Thanks!
The Webmaster

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

mail($email_address, $subject, $message, 
"From: Virtual Hell Webmaster<william@eustadia.zeroconcept.net>\n 
X-Mailer: PHP/" . phpversion()); 

echo "Your membership information has been mailed to your email address! Please check it and follow the directions!";

?>
I've tested that out on my server and it works fine. The problem was the extra } after the echo.

-Nay

Posted: Mon Sep 22, 2003 4:08 am
by Tortured911
Now, If I use that...it makes a parse error message...Do I need to do something in particular that doesn't have to do with editing the coding?

BTW...here's the full coding:
PHP wrote:<?

include 'db.php';

// Define post fields into simple variables
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$info = $_POST['info'];

/* Let's strip some slashes in case the user entered
any escaped characters. */

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$info = stripslashes($info);


/* Do some error checking on the form posted fields */

if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
echo 'You did not submit the following required information! <br />';
if(!$first_name){
echo "First Name is a required field. Please enter it below.<br />";
}
if(!$last_name){
echo "Last Name is a required field. Please enter it below.<br />";
}
if(!$email_address){
echo "Email Address is a required field. Please enter it below.<br />";
}
if(!$username){
echo "Desired Username is a required field. Please enter it below.<br />";
}
include 'join_form.php'; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}

/* Let's do some checking and ensure that the user's email address or username
does not exist in the database */

$sql_email_check = mysql_query("SELECT email_address FROM users
WHERE email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users
WHERE username='$username'");

$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

if(($email_check > 0) || ($username_check > 0)){
echo "Please fix the following errors: <br />";
if($email_check > 0){
echo "<strong>Your email address has already been used by another member
in our database. Please submit a different Email address!<br />";
unset($email_address);
}
if($username_check > 0){
echo "The username you have selected has already been used by another member
in our database. Please choose a different Username!<br />";
unset($username);
}
include 'join_form.php'; // Show the form again!
exit(); // exit the script so that we do not create this account!
}

/* Everything has passed both error checks that we have done.
It's time to create the account! */

/* Random Password generator.
http://www.phpfreaks.com/quickcode/Rand ... tor/56.php

We'll generate a random password for the
user and encrypt it, email it and then enter it into the db.
*/

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);

// Enter info into the Database.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO users (first_name, last_name,
email_address, username, password, info, signup_date)
VALUES('$first_name', '$last_name', '$email_address',
'$username', '$db_password', '$info2', now())")
or die (mysql_error());

if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
$userid = mysql_insert_id();

// Let's mail the user!
$subject = "Your Membership at Virtual Hell!";
$message = "Dear $first_name $last_name,
Thank you for registering!

You are two steps away from logging in and accessing our exclusive members area.

To activate your membership,
please click here: http://www.eustadia.zeroconcept.net/wil ... b_password

Once you activate your membership, you will be able to login
with the following information:
Username: $username
Password: $random_password

Thanks!
The Webmaster

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

mail($email_address, $subject, $message,
"From: Virtual Hell Webmaster<william@eustadia.zeroconcept.net>\n
X-Mailer: PHP/" . phpversion());
echo 'Your membership information has been mailed to your email address!
Please check it and follow the directions!';
}

?>
I tried to use what you did...didn't work... :( Users have to be activated before they can login too...What do I do? Thanks.

Posted: Mon Sep 22, 2003 4:13 am
by JayBird
you do need the closing curly brace, but Nay thought otherwise becuase you didn't show your entire code.

Mark

Posted: Mon Sep 22, 2003 4:16 am
by Nay
Yeah, I was scratching my head for a while thinking what it was supposed to end. Anyhow, what line was the parse error on? It should tell you.

-Nay

Posted: Mon Sep 22, 2003 4:25 am
by Tortured911
Well, since I put that } back in, the parse error is gone... It says:

"Your membership information has been mailed to your email address! Please check it and follow the directions! " when I test register, but it doesn't send the verification email. I had even used my own email address before that to see if it was just my email address, and it wasn't...any ideas?

Posted: Mon Sep 22, 2003 4:32 am
by JayBird
you could try using \r\n instead of just \n on this line

Code: Select all

"From: Virtual Hell Webmaster<william@eustadia.zeroconcept.net>\n
Mark

Posted: Mon Sep 22, 2003 4:47 am
by Nay
mMm, It might be your mail server. Since the code is quite okay from what I see. Can you try just mail() with some crap in it? See if that mail gets sent.

-Nay

ps, Bech100, I never see you on ICQ lol

Posted: Mon Sep 22, 2003 4:55 am
by JayBird
from the manual
You must use \r\n to separate headers, although some Unix mail transfer agents may work with just a single newline (\n).
Which is maybe why it works for Nay and not for you, but apart from that, i can't see anything else wrong with your code.

Nay : I keep looking out for you, but i haven't see you online yet...must not meant to be :)

Posted: Mon Sep 22, 2003 5:00 am
by Nay
lol, I am online now. I see you're not. I meant look at the ICQ thing on your profile. It's red!!! eek ><.

-Nay

Posted: Mon Sep 22, 2003 5:03 am
by JayBird
on my screen, the ICQ icon is in green, saying i am online, even though i am not. I don't have ICQ installed on my machine at work.