I have a server at my house running mysql and other server tools so I can run the Ro Private server I created. The Ro server is non profit (of course) and my friends and I just wanted to take on a challenge. We finally have the entire server up and running except the registration part. I need to add the custom registration code I created to the website (The registration code is 1/2 Html and 1/2 pp). I was wondering if this was possible?I will not be editing any base strings to the website, I will just be adding a seperate registration button that allows connection to my server computer. I was also wondering where to put the code and how I would be doing this.
Heres the Information I have on adding the Registration code.
-------------------------------------------------------------------------------------------------------
User Registration (register.php)
Now we can have a page where the user can register their account. It will be part HTML and part PHP. It can look as follows:
Sample Code
<html></html><form action="register.php" method="post">
Username: <input name="username" type="text" />
Password: <input type="password" name="password" />
Email: <input name="email" type="text" />
<input type="submit" value="Submit" />
</form>
Copyright exforsys.com
The basic HTML structure of the registration form is shown above. We can add some PHP code to handle the actual registration part. The form will send the information through POST, and we can handle it with PHP. We will take the username, make sure it does not exist, then create the account using mysql_query() to place the values within the database.
Sample Code
<?php
include("db.php");
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email']))
{
//Prevent SQL injections
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
//Get MD5 hash of password
$password = md5($_POST['password']);
//Check to see if username exists
$sql = mysql_query("SELECT username FROM usersystem WHERE username = 'username'");
If (mysql_num_rows($s?>0))
{
die ("Username taken.");
}
mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( '$username', '$password', '$email')") or die (mysql_error()); echo "Account created."
}
?>
<html></html>
<form action="register.php" method="post">
Username: <input name="username" type="text" />
Password: <input type="password" name="password" />
Email: <input name="email" type="text" />
<input type="submit" value="Submit" />
</form>
Copyright exforsys.com
The login page (login.php)
Final let us create the login page. For login.php, we can have a form for the username and password, then we pass those values to the user_login() function we made earlier in the db.php script.
We can once again have a basic HTML structure for login.php
Sample Code
<html></html>
<form action="login.php" method="post">
Username: <input name="username" type="text" />
Password: <input type="password" name="password" />
<input type="submit" value="Submit" />
</form>
Copyright exforsys.com
Now, we can add the PHP code before the HTML again to process the login, just like with the registration.
We do not really need to add much code, because most of it was done in the db.php page. Here is what you need:
Sample Code
<?php
include("db.php");
if (isset($_POST['username'] && isset($_POST['password']))
{
user_login($_POST['username'], $_POST['password']);
}
?>
<html></html>
<form action="login.php" method="post">
Username: <input name="username" type="text" />
Password: <input type="password" name="password" />
</form>
Copyright exforsys.com
You now have everything you need for your user system. For all of the pages on your website, you must place this line at the very first line for this to work:
Sample Code
<?php include "db.php";?>
You can then show their username like so:
<?php echo "Logged in as: " . $_SESSION['username'];?>
Copyright exforsys.com
That completes the demonstration on how to implement a user login/membership system in your website.
Here's another page from the same subject on the source site. It was to long to paste here.
More Info:
I'm sorry that it was so much to read, I just couldn't find a way to summarize it without leaving important details out. I appreciate any help
-Thank you ^.^
Heres the Information I have on adding the Registration code.
-------------------------------------------------------------------------------------------------------
User Registration (register.php)
Now we can have a page where the user can register their account. It will be part HTML and part PHP. It can look as follows:
Sample Code
<html></html><form action="register.php" method="post">
Username: <input name="username" type="text" />
Password: <input type="password" name="password" />
Email: <input name="email" type="text" />
<input type="submit" value="Submit" />
</form>
Copyright exforsys.com
The basic HTML structure of the registration form is shown above. We can add some PHP code to handle the actual registration part. The form will send the information through POST, and we can handle it with PHP. We will take the username, make sure it does not exist, then create the account using mysql_query() to place the values within the database.
Sample Code
<?php
include("db.php");
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email']))
{
//Prevent SQL injections
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
//Get MD5 hash of password
$password = md5($_POST['password']);
//Check to see if username exists
$sql = mysql_query("SELECT username FROM usersystem WHERE username = 'username'");
If (mysql_num_rows($s?>0))
{
die ("Username taken.");
}
mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( '$username', '$password', '$email')") or die (mysql_error()); echo "Account created."
![Wink](https://2img.net/i/fa/i/smiles/icon_wink.gif)
}
?>
<html></html>
<form action="register.php" method="post">
Username: <input name="username" type="text" />
Password: <input type="password" name="password" />
Email: <input name="email" type="text" />
<input type="submit" value="Submit" />
</form>
Copyright exforsys.com
The login page (login.php)
Final let us create the login page. For login.php, we can have a form for the username and password, then we pass those values to the user_login() function we made earlier in the db.php script.
We can once again have a basic HTML structure for login.php
Sample Code
<html></html>
<form action="login.php" method="post">
Username: <input name="username" type="text" />
Password: <input type="password" name="password" />
<input type="submit" value="Submit" />
</form>
Copyright exforsys.com
Now, we can add the PHP code before the HTML again to process the login, just like with the registration.
We do not really need to add much code, because most of it was done in the db.php page. Here is what you need:
Sample Code
<?php
include("db.php");
if (isset($_POST['username'] && isset($_POST['password']))
{
user_login($_POST['username'], $_POST['password']);
}
?>
<html></html>
<form action="login.php" method="post">
Username: <input name="username" type="text" />
Password: <input type="password" name="password" />
</form>
Copyright exforsys.com
You now have everything you need for your user system. For all of the pages on your website, you must place this line at the very first line for this to work:
Sample Code
<?php include "db.php";?>
You can then show their username like so:
<?php echo "Logged in as: " . $_SESSION['username'];?>
Copyright exforsys.com
That completes the demonstration on how to implement a user login/membership system in your website.
Here's another page from the same subject on the source site. It was to long to paste here.
More Info:
I'm sorry that it was so much to read, I just couldn't find a way to summarize it without leaving important details out. I appreciate any help
-Thank you ^.^
Last edited by matchan2 on August 13th 2010, 12:10 am; edited 1 time in total