Well i'm learning php and this is the first major thing i have done. If you find any error i'm happy for suggestions to fix it. First create a database in cpanel with username and password like you would normally. Go to PHPmyadmin ( i will update this later to the php way to create the database) Create a table members Number of fields 13: Coding: Index.php <? session_start(); if(isset($_SESSION['username'])){ echo $_SESSION["username"]; } else { ?> <a href="http://mystatsviewer.com/signup.php"> Sign up</a> <a href="http://mystatsviewer.com/login.php"> Login</a> <?php } ?> PHP: Signup.php: <script language="javascript"> function DoSubmit () { if (document.form1.username.value == "") { alert ("NO username Entered!"); document.form1.username.focus(); return ""; } if (document.form1.password.value == "") { alert ("NO Password Entered!"); document.form1.password.focus(); return ""; } if (document.form1.Email.value == "") { alert ("NO E-mail Entered!"); document.form1.Email.focus(); return ""; } document.form1.submit(); } </script> <?php /* Add the database */ include("include/config.php"); mysql_connect($host, $dbase_user, $dbase_pass); @mysql_select_db($db_name) or die( "No connection"); /* Check if already signed up */ /* collect form information -password */ $username = mysql_real_escape_string($_POST['username']); $email = mysql_real_escape_string($_POST['Email']); $gamertag = mysql_real_escape_string($_POST['Gamertag']); $aim = mysql_real_escape_string($_POST['aim']); $msn = mysql_real_escape_string($_POST['msn']); $Location = mysql_real_escape_string($_POST['Location']); $Website = mysql_real_escape_string($_POST['Website']); $ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']); /* Password to encyrpt */ $pass = mysql_real_escape_string($_POST['password']); $password = md5(sha1($pass)); if($username == "" || $email == "" || $password == "") { ?> <form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Username: <input type="text" name="username" /> Password: <input type="text" name="password" /> E-mail: <input type="text" name="Email" /> Gamertag: <input type="text" name="Gamertag" /> AIM: <input type="text" name="aim" /> MSN: <input type="text" name="msn" /> Location: <input type="text" name="Location" /> Website: <input type="text" name="website" /> <input type="button" onclick="DoSubmit ()" value="Submit"> </form> <?php } else { $result = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error()); if(mysql_num_rows($result)!==0) { echo "username already exists"; ?> <form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Username: <input type="text" name="username" /> Password: <input type="text" name="password" /> E-mail: <input type="text" name="Email" /> Gamertag: <input type="text" name="Gamertag" /> AIM: <input type="text" name="aim" /> MSN: <input type="text" name="msn" /> Location: <input type="text" name="Location" /> Website: <input type="text" name="website" /> <input type="button" onclick="DoSubmit();" value="Submit"> </form> <?php } else { $result2 = mysql_query("SELECT * FROM `members` WHERE `E-mail` = '$email'") or die(mysql_error()); if(mysql_num_rows($result2)!==0) { ?> <form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Username: <input type="text" name="username" /> Password: <input type="text" name="password" /> echo "E-mail already exists"; E-mail: <input type="text" name="Email" /> Gamertag: <input type="text" name="Gamertag" /> AIM: <input type="text" name="aim" /> MSN: <input type="text" name="msn" /> Location: <input type="text" name="Location" /> Website: <input type="text" name="website" /> <input type="button" onclick="DoSubmit();" value="Submit"> </form> <?php } else { $result3 = mysql_query("SELECT * FROM `members` WHERE `ip` = '$ip'") or die(mysql_error()); if(mysql_num_rows($result3)!==0) { echo "Your IP already signed up"; ?> <form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Username: <input type="text" name="username" /> Password: <input type="text" name="password" /> E-mail: <input type="text" name="Email" /> Gamertag: <input type="text" name="Gamertag" /> AIM: <input type="text" name="aim" /> MSN: <input type="text" name="msn" /> Location: <input type="text" name="Location" /> Website: <input type="text" name="website" /> <input type="button" onclick="DoSubmit ()" value="Submit"> </form> <?php } else { mysql_query("INSERT INTO members (`username`,`password`,`E-mail`,`Joined`,`Group`,`Last_Activate`,`IP`,`Gamertag`,`AIM`,`MSN`,`Website`,`Location`) VALUES('$_POST[username]','$password','$_POST[Email]','".time()."','Member','".time()."','$ip','$_POST[Gamertag]','$_POST[aim]','$_POST[msn]','$_POST[Website]','$_POST[Location]')") or die(mysql_error()); echo " Thank you for signing up ".$username; } } } } ?> PHP: Login.php <?php session_start(); ?> <head> <script language="javascript"> function DoSubmit () { if (document.form1.username.value == "") { alert ("NO username Entered!"); document.form1.username.focus(); return ""; } if (document.form1.password.value == "") { alert ("NO Password Entered!"); document.form1.password.focus(); return ""; } document.form1.submit(); } </script> </head> <body> <?php /* Add the database */ include("include/config.php"); mysql_connect($host, $dbase_user, $dbase_pass); @mysql_select_db($db_name) or die( "No connection"); /* Check if already signed up */ /* collect form information -password */ $username = mysql_real_escape_string($_POST['username']); /* Password to encyrpt */ $pass = mysql_real_escape_string($_POST['password']); $password = md5(sha1($pass)); if($username == "" || $password == "") { ?> <form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Username: <input type="text" name="username" /> Password: <input type="text" name="password" /> <input type="button" onclick="DoSubmit ()" value="Submit"> </form> <?php } else { $result = mysql_query("SELECT * FROM `members` WHERE `username` = '$username' AND `password` = '$password'") or die(mysql_error()); if(mysql_num_rows($result)!==1) { ?> <form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Invald username or password Username: <input type="text" name="username" /> Password: <input type="text" name="password" /> <input type="button" onclick="DoSubmit ()" value="Submit"> </form> <?php } Else { echo " Thank you for logging in ".$username; $_SESSION['username']=$username; ?> <a href="http://mystatsviewer.com/">Home Page</a> <?php } } ?> </body> PHP: logout.php: <?php session_start(); session_destroy(); ?> PHP: Now create a folder and call it include. now add config.php config.php: <?php $host = "localhost"; //SQL host normally localhost $dbase_user = "nukezill_login"; // database username $dbase_pass = "1521"; // database password $db_name = "nukezill_login"; // Database name $dbase_pre = ""; // table prefix if apply mysql_connect(localhost, $dbase_user, $dbase_pass); @mysql_select_db($db_name) or die( "No connection"); ?> PHP: This should be a easy enough script to change layout and add to the index page and how to set up other pages Enjoy NukeZilla
Looks nice. Only I would suggest not displaying empty forms when the user provides bad form data. Meaning instead of showing a empty input again, showing it like: AIM: <input type="text" name="aim" value="<?php echo $_POST['aim']; ?>" /> People actually hate forms they have to entirely again because of mistyping something. This is a short form so that doesn't matter so much but it's only a hint