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?
PHP Register/Login Help...
Moderator: General Moderators
-
Tortured911
- Forum Newbie
- Posts: 5
- Joined: Sun Sep 21, 2003 11:52 pm
PHP Register/Login Help...
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?
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?
I would start here:
viewtopic.php?t=6521
viewtopic.php?t=6521
-
Tortured911
- Forum Newbie
- Posts: 5
- Joined: Sun Sep 21, 2003 11:52 pm
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.
"$_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.
Make another file called signup.php. Do it something like:
Hope that helps,
-Nay
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;
}
?>-Nay
-
Tortured911
- Forum Newbie
- Posts: 5
- Joined: Sun Sep 21, 2003 11:52 pm
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:

Here's the code:
What do I do? It's not working...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!';
}
?>
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!";
?>-Nay
-
Tortured911
- Forum Newbie
- Posts: 5
- Joined: Sun Sep 21, 2003 11:52 pm
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:
Users have to be activated before they can login too...What do I do? Thanks.
BTW...here's the full coding:
I tried to use what you did...didn't work...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!';
}
?>
-
Tortured911
- Forum Newbie
- Posts: 5
- Joined: Sun Sep 21, 2003 11:52 pm
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?
"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?
you could try using \r\n instead of just \n on this line
Mark
Code: Select all
"From: Virtual Hell Webmaster<william@eustadia.zeroconcept.net>\nfrom the manual
Nay : I keep looking out for you, but i haven't see you online yet...must not meant to be
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.You must use \r\n to separate headers, although some Unix mail transfer agents may work with just a single newline (\n).
Nay : I keep looking out for you, but i haven't see you online yet...must not meant to be