Old 22-05-2008, 15:08   #1 (permalink)
pesokow
How do I mine for fish?!
 
pesokow's Avatar
 
Join Date: May 2008
Posts: 6
Need a registration page!

Hey everyone;
I'm not really good at PHP. I have used Jesusfreak101's tutorial and got most of it but it seems that he doesn't have a registration page.

Can anyone help me on it? All I need is a reg. page!
  Reply With Quote
Old 22-05-2008, 15:38   #2 (permalink)
LukeV
Best custom title ever.
 
LukeV's Avatar
 
Join Date: Apr 2008
Posts: 205
Here's the registration script I have going on my site. Read through it and let me know if you have any difficulties. Oh and I recommend you start reading from "if ($good == false) {"/

PHP Code:
<?php
    $good 
false;
      if (isset(
$_POST['submit'])) {
        
$username mysql_real_escape_string($_POST['username']);
        
$email mysql_real_escape_string($_POST['email']);
        
$error_string="";
        
$check mysql_query("SELECT * FROM users WHERE username = '$username'");
        
$check_email mysql_query("SELECT * FROM users WHERE email = '$email'");
        if (
mysql_num_rows($check) > 0) {$error_string .= "This username is already being used!<br />";}
        if (
mysql_num_rows($check_email) > 0) {$error_string .= "This email is already registered!<br />";}
        if ((
$len strlen($username)) < || $len 15) {$error_string .= "The username must be between 4-15 characters long!<br />";}
        if ((
$len strlen($_POST['password'])) < || $len 15) {$error_string .= "The password must be between 4-15 characters long!<br/>";}
        if (!
preg_match("/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i"$email)) {$error_string .= "The email is not valid!";}
    
        if (
$error_string == "") {
        
$result mysql_query("SELECT * FROM fcontrol WHERE ip = '{$_SERVER['REMOTE_ADDR']}'");
        
        if (
mysql_num_rows($result) == 0) {
            
mysql_query("INSERT INTO fcontrol VALUES ('{$_SERVER['REMOTE_ADDR']}', " time() . ", 0)");
            
$good true;
        } else {
            
$ip mysql_fetch_assoc($result);
            if (
$ip['register'] < time() - 60 60 24 7) { 
                
$good true
                
mysql_query("UPDATE fcontol SET register = " time() . " WHERE ip = '{$_SERVER['REMOTE_ADDR']}'");
            }  else {
            
                echo 
"<h2>Error</h2> <p>You have already registered an account. If you lost your login information you may request it here.</p>";
            }
            }
        if (
$good == true) {
        
mysql_query("INSERT INTO users (username, password, type, email) VALUES (\"$username\", \"" md5($_POST['password']) . "\", \"user\", \"$email\")");  
        
?> 
        <h2>Congratulations</h2><p>You have successfully registered an account. You may now login.</p>
        <?php   
        
}     
    } else {
        echo 
"<h2>Error</h2><p>$error_string</p>";
    }
    }
?>

<?php
if ($good == false) {
?>

<h2> Register</h2>

        <form action="/register.php" method="post" id="register">
        <label>Username:</label><input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>"/>
<br/> 
        <label>Password:</label><input type="password" name="password"/><br/>
        <label>E-mail:</label><input type="text" name="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"/><br/><br/>
        <input class="submit" type="image" src="img/register.gif" alt="Register" name="submit" value="Register"><br/> 
         </form>

<?php ?>

Last edited by LukeV : 30-05-2008 at 12:53.
  Reply With Quote
Old 30-05-2008, 09:06   #3 (permalink)
pesokow
How do I mine for fish?!
 
pesokow's Avatar
 
Join Date: May 2008
Posts: 6
Thanks =)

Thanks, I will let you know, if I have any problems with it. I had to format my comp and I lost my stuff -.-! So, after I find JesusFreak's login system I will try and put the reg page you gave me. I will then let you know if I have any problems

Thanks again!
  Reply With Quote
Old 18-06-2008, 14:50   #4 (permalink)
jesusfreak101
ie must die
 
jesusfreak101's Avatar
 
Join Date: Jun 2007
Location: Washington
Posts: 382
Send a message via AIM to jesusfreak101
idk if u still need this, but this was my registration page:

PHP Code:
<?php
include('db.php');
//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['firstname'] | !$_POST['lastname'] | !$_POST['email']) {
die(
'You did not complete all of the required fields');
}

// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck $_POST['username'];
$check mysql_query("SELECT username FROM members WHERE username = '$usercheck'")
or die(
mysql_error());
$check2 mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die(
'Sorry, the username '.$_POST['username'].' is already in use.');
}

// checks if the email is in use
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$emailcheck $_POST['email'];
$check mysql_query("SELECT email FROM members WHERE email = '$emailcheck'")
or die(
mysql_error());
$check2 mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die(
'Sorry, the email '.$_POST['email'].' is already in use.');
}


// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die(
'Your passwords did not match. ');
}

// here we encrypt the password and add slashes if needed
$_POST['pass'] = ($_POST['pass']);
if (!
get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}

// now we insert it into the database
$insert "INSERT INTO members (username, user_password, firstname, lastname, email)
VALUES ('"
.$_POST['username']."', '".$_POST['pass']."','".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['email']."')";
$add_member mysql_query($insert);
?>
<!--------------------------- HTML/CSS --------------------------->
<html>
<head>
<title></title>
</head>
<body>
Thank you, you have registered - <a href="index.php">you may now login</a>
</body>
</html>
<!--------------------------- END --------------------------->


<?php
}
else
{
?>

<!--------------------------- HTML/CSS --------------------------->
<html>
<head>
<title></title>
</head>
<body>
Registration
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
First Name:<br /> <input type="text" name="firstname" maxlength="15"><br />
Last Name:<br /> <input type="text" name="lastname" maxlength="15"><br />
Email:<br /> <input type="text" name="email" maxlength="40"><br />
Username:<br /> <input type="text" name="username" maxlength="60"><br />
Password:<br /> <input type="password" name="pass" maxlength="10"><br />
Confirm Password:<br /> <input type="password" name="pass2" maxlength="10"><br />
<input type="submit" name="submit" value="Register">
</form>

</body>
</html>


<!--------------------------- END --------------------------->
<?php
}
?>


There are two parts of the HTML, the first one is after they have registered it will show them that page. The second one is where they register all of their info. You can tweak it to how ever u like...this worked for me. let me know if you have any questions

also dont forget this is all set for my DB and Tables, so dont just copy and paste. took me a while to get it
  Reply With Quote
Old 18-06-2008, 14:54   #5 (permalink)
pesokow
How do I mine for fish?!
 
pesokow's Avatar
 
Join Date: May 2008
Posts: 6
Thanks, the registration page I have is working but I just can't log in, I can maybe use it with you login system.
  Reply With Quote
Old 18-06-2008, 14:58   #6 (permalink)
jesusfreak101
ie must die
 
jesusfreak101's Avatar
 
Join Date: Jun 2007
Location: Washington
Posts: 382
Send a message via AIM to jesusfreak101
Quote:
Originally Posted by pesokow
Thanks, the registration page I have is working but I just can't log in, I can maybe use it with you login system.
do u get an error? or does the page just reload?

could u post a link?
  Reply With Quote
Old 19-06-2008, 04:36   #7 (permalink)
pesokow
How do I mine for fish?!
 
pesokow's Avatar
 
Join Date: May 2008
Posts: 6
I haven't uploaded it yet, I was testing it on my computer...
  Reply With Quote
Old 19-06-2008, 05:34   #8 (permalink)
LukeV
Best custom title ever.
 
LukeV's Avatar
 
Join Date: Apr 2008
Posts: 205
Quote:
Originally Posted by pesokow
Thanks, the registration page I have is working but I just can't log in, I can maybe use it with you login system.

Well that probably means there a communication error between the database. Make sure you type all your database info right and it should work.
  Reply With Quote
Old 19-06-2008, 06:33   #9 (permalink)
pesokow
How do I mine for fish?!
 
pesokow's Avatar
 
Join Date: May 2008
Posts: 6
Well, the registration page you gave me work fine but it keeps opening the login page even if I login correctly! (The code that LukeV gave) Here is the login page you gave;

PHP Code:
<?php include 'db.php';
if (!isset(
$_SESSION['user_id'])) {?> 
    <form action="login.php" method="post" id="login">    
    <div> 
    <label>Username: </label><input type="text" name="username" value="<?php if (isset($_SESSION['failed_username'])) echo $_SESSION['failed_username']; ?>"/>        
    <label>Password: </label><input type="password" name="password" />       
    <input type="submit" name="login" value="Login" />
    </div>      
    </form>         
    <a class="links" href="register.php">Register</a>      
  <?php }else{           
    echo 
"<span>Welcome <a href=\"#\">{$_SESSION['user_name']}!</a></span>"?>
    <a class="links" href="logout.php">Logout</a> <?php           
              
?>

and this is the db page;

PHP Code:
<?php
$connection 
mysql_connect("localhost""***""****");
$db_select mysql_select_db("****"$connection);
session_start();
?>

Thanks again
  Reply With Quote
Old 19-06-2008, 07:45   #10 (permalink)
LukeV
Best custom title ever.
 
LukeV's Avatar
 
Join Date: Apr 2008
Posts: 205
Hey mate I just noticed I didn't give you login.php The code above is not the actually login process it just decides whether or not to show the login form.

I use that code on my index page (the header to be exact so the login form is visible wherever the user is. So after the user hits submit it should direct to login.php (action="login.php") which processes the login and then redirects the user to the index again (header("location:./")

Here's the login process:

PHP Code:
<?php
include("config.php");
$username mysql_real_escape_string($_POST['username']);
$password md5($_POST['password']);  

$result mysql_query("SELECT * FROM users WHERE username = \"$username\" AND password = \"$password\"");
  if (
mysql_num_rows($result) > 0) {
    
$user mysql_fetch_assoc($result);
    
$_SESSION['user_id'] = $user['id'];
    
$_SESSION['user_name'] = $user['username'];
}else{
$_SESSION['failed_username'] = $_POST['username'];
}
header("location:./");
?>

I think you need to replace config.php with db.php whatever you called the file that connects with the database.

If you want to the login page to be on a unique page you can change action="login.php" to whatever you call the above file.
  Reply With Quote
Old 19-06-2008, 12:20   #11 (permalink)
jesusfreak101
ie must die
 
jesusfreak101's Avatar
 
Join Date: Jun 2007
Location: Washington
Posts: 382
Send a message via AIM to jesusfreak101
also another small note, which ever encryption you use (md5, sha1) make sure you stick with it on the whole site because if you have two of them it will not work. that happened to me. My encryption on my pages are sha1. LukeV is using md5

also make sure when they click on "Login" it is linked to login.php
  Reply With Quote
Old 19-06-2008, 12:22   #12 (permalink)
jesusfreak101
ie must die
 
jesusfreak101's Avatar
 
Join Date: Jun 2007
Location: Washington
Posts: 382
Send a message via AIM to jesusfreak101
Quote:
Originally Posted by pesokow
I haven't uploaded it yet, I was testing it on my computer...
i hope your not testing all the php pages on your computer to see if they're functional. You need a server for PHP to work, you can't use your computer.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8