Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
[PHP] Membership system.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Alam" data-source="post: 73394" data-attributes="member: 4147"><p>Hello,</p><p>Here is a basic & simple PHP script wrote from scratch on my own.</p><p> </p><p>The system includes :</p><ul> <li data-xf-list-type="ul">Login page</li> <li data-xf-list-type="ul">Config page</li> <li data-xf-list-type="ul">Registration page</li> <li data-xf-list-type="ul">Md5 encryption</li> <li data-xf-list-type="ul">Members page</li> <li data-xf-list-type="ul">Logout page</li> <li data-xf-list-type="ul">account page (change username & password)</li> <li data-xf-list-type="ul">Simple database structure.</li> </ul><p>--</p><p>Config page :</p><p> </p><p>[PHP]<?php</p><p> </p><p>$dbhost = "localhost";</p><p>$dbuser = "root";</p><p>$dbpass = "";</p><p>$dbname = "php";</p><p> </p><p> </p><p>mysql_connect($dbhost,$dbuser,$dbpass);</p><p>mysql_select_db($dbname);</p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p>?>[/PHP]</p><p> </p><p>Index/Login page :</p><p> </p><p>[PHP]<?php</p><p>session_start();</p><p> </p><p>include 'config.php';</p><p> </p><p>$username = mysql_real_escape_string($_POST['username']);</p><p>$password = $_POST['password'];</p><p> </p><p>if(isset($_POST['submit']))</p><p>{</p><p>if(!empty($username)&&!empty($password))</p><p>{</p><p> $query = mysql_query("SELECT * FROM users WHERE username='$username'");</p><p> $id1 = mysql_query("SELECT id FROM users WHERE username='$username'");</p><p> $numrows = mysql_num_rows($query);</p><p> </p><p> while ($row = mysql_fetch_array($id1))</p><p> {</p><p> $id = $row['id'];</p><p> }</p><p> </p><p> </p><p> if($numrows!=0)</p><p> {</p><p> while ($row = mysql_fetch_assoc($query))</p><p> {</p><p> $user = $row['username'];</p><p> $pass = $row['password'];</p><p> }</p><p> </p><p> if($username==$user&&md5($password)==$pass)</p><p> {</p><p> $_SESSION['user']=$username;</p><p> $_SESSION['user_id']=$id;</p><p> header("location: me.php");</p><p> </p><p> }</p><p> else</p><p> echo "Your password is incorrect, please try again.";</p><p> </p><p> }</p><p> else</p><p> echo "The user $username does not exist";</p><p> </p><p>}</p><p>else</p><p> echo "Please enter your username and password.";</p><p> </p><p>}</p><p> </p><p>if($_SESSION['user'])</p><p>{</p><p> header("location: me.php");</p><p>}</p><p>else</p><p>{</p><p>echo "<html></p><p> <head></p><p> <title>Login page</title></p><p> </head></p><p> </p><p> <body></p><p> <form action='index.php' method='POST'></p><p> Username : <input type='text' name='username'></p><p> Password : <input type='password' name='password'></p><p> <input type='submit' name='submit' value='Login'></p><p> </form></p><p> </p><p> </body></p><p></html>";</p><p> </p><p>?></p><p>[/PHP]</p><p> </p><p>Registration Page :</p><p>[PHP]</p><p><?php</p><p>include 'config.php';</p><p> </p><p>$username = strip_tags($_POST['username']);</p><p>$email = strip_tags($_POST['email']);</p><p>$password = strip_tags($_POST['password']);</p><p>$repeatpassword = strip_tags($_POST['repeatpassword']);</p><p> </p><p> </p><p>if (isset($_POST['submit'])) {</p><p> </p><p> </p><p> if ($username && $email && $password && $repeatpassword) {</p><p> if ($password == $repeatpassword) {</p><p> if (strlen($username) > 30) {</p><p> echo "Your username can't be longer than 30 characters.";</p><p> } else {</p><p> if (strlen($email) < 6) {</p><p> echo "This email is invalid.";</p><p> } else {</p><p> if (strlen($password) > 35 || strlen($password) < 6) {</p><p> echo "Your password must be between 6 and 35 characters.";</p><p> } else {</p><p> $ch = mysql_query("SELECT username FROM users WHERE username='$username'");</p><p> $check = mysql_num_rows($ch);</p><p> </p><p> if ($check != 0) {</p><p> echo "The username $username already exists.";</p><p> } else {</p><p> </p><p> $hashpassword = md5($password);</p><p> $insert = "INSERT INTO users (username,email,password) VALUES ('$username','$email','$hashpassword')";</p><p> mysql_query($insert);</p><p> $_SESSION['user']=$username;</p><p> $_SESSION['user_id']=$id;</p><p> header("location: me.php");</p><p> }</p><p> }</p><p> }</p><p> }</p><p> }</p><p> else</p><p> echo "Password does not match";</p><p> }</p><p> else</p><p> echo "Please fill in all the fields";</p><p> </p><p> }</p><p> </p><p> </p><p>?></p><p> </p><p> </p><p> </p><p> </p><p> </p><p><html></p><p> <head></p><p> <title>Register page</title></p><p> </head></p><p> </p><p> <body></p><p> <form action="register.php" method="POST"></p><p> Username</p><p> <br /></p><p> <input type="text" name="username"></p><p> <br /></p><p> Email</p><p> <br /></p><p> <input type="text" name="email"></p><p> <br /></p><p> Password</p><p> <br /></p><p> <input type="password" name="password"></p><p> <br /></p><p> Repeat password</p><p> <br /></p><p> <input type="password" name="repeatpassword"></p><p> <br /></p><p> <input type="submit" name="submit" value="Create account"></p><p> </p><p> </p><p> </form></p><p> </p><p> </body></p><p> </p><p> </p><p></html>[/PHP]</p><p> </p><p>Me.php page :</p><p>[PHP]<?php</p><p>session_start();</p><p> </p><p>if($_SESSION['user'])</p><p>{</p><p> echo "<a href='me.php'>". $_SESSION['user'] ."</a> |";</p><p> echo " <a href='account.php'>My account </a> |<a href='logout.php'>Logout</a>";</p><p>}</p><p>else</p><p> echo "You must be logged in to view this page.";</p><p> </p><p>?>[/PHP]</p><p> </p><p>Logout page :</p><p>[PHP]<?php</p><p> </p><p>session_start();</p><p> </p><p>session_destroy();</p><p> </p><p>header("location: index.php");</p><p> </p><p>?>[/PHP]</p><p> </p><p>Account page :</p><p>[PHP]</p><p><?php</p><p> </p><p>session_start();</p><p> </p><p> $username = strip_tags($_POST['username']);</p><p> $cpassword = $_POST['cpassword'];</p><p> $npassword = $_POST['npassword'];</p><p> mysql_connect("localhost", "root", "");</p><p> mysql_select_db("php");</p><p> $update = "UPDATE users SET username = '$username' WHERE id = '". $_SESSION['user_id'] ."'";</p><p> $check = mysql_query("SELECT username FROM users WHERE username='$username'");</p><p> $pwcheck = mysql_query("SELECT password FROM users WHERE username='$username'");</p><p> $numrows = mysql_num_rows($check);</p><p> </p><p>if (isset($_POST['eu'])) {</p><p> </p><p> </p><p> </p><p> if ($username) {</p><p> </p><p> if ($numrows!=0)</p><p> </p><p> {</p><p> echo "This username already exists!";</p><p> }</p><p> else</p><p> {</p><p> mysql_query($update);</p><p> session_start();</p><p> </p><p> session_destroy();</p><p> </p><p> header("location: logout.php");</p><p> }</p><p> </p><p> }</p><p> else</p><p> echo "Please enter a username";</p><p> </p><p>}</p><p>else</p><p>{</p><p> if(isset($_POST['ue']))</p><p> </p><p> {</p><p> </p><p> if ($cpassword&&$npassword)</p><p> {</p><p> </p><p>while($row = mysql_fetch_assoc($pwcheck))</p><p>{</p><p> $dbpass = $row['password'];</p><p>}</p><p> </p><p>$hcpassword = md5($cpassword);</p><p>$hnpassword = md5($npassword);</p><p> </p><p>if ($hcpassword==$dbpass)</p><p>{</p><p> if (strlen($npassword)>35 || strlen($npassword)<6)</p><p> {</p><p> echo "Your password must be between 6 and 25 characters.";</p><p> }</p><p> else</p><p> {</p><p> $updatepass = "UPDATE users SET password = '$hnpassword' WHERE id='". $_SESSION['user_id'] ."'";</p><p> mysql_query($updatepass);</p><p> echo "Your password has been changed.";</p><p> }</p><p>}</p><p>else</p><p>{</p><p> echo "This is not your current password.";</p><p>}</p><p> }</p><p> else</p><p> echo "Please field in both fields.";</p><p> </p><p> }</p><p>}</p><p> </p><p>if (!$_SESSION['user_id']) {</p><p> echo "you must be logged in to view this page";</p><p>} else {</p><p> echo "<head></p><p> <title>My account</title></p><p> </head></p><p> </p><p> <body></p><p> </p><p> <form action='account.php' method='POST'></p><p> <h1>Username</h1> <a href='me.php'>Go back</a></p><p> Edit username <br /> <input type='text' name='username'> <input type='submit' name='eu' value='Update account'></form></p><p> </form></p><p> <form action='account.php' method='POST'><br /></p><p> <h1>Change password</h1></p><p> <input type=\"hidden\" name=\"username\" value=\"". $_SESSION['user'] ."\" /></p><p> Current password <br/> <input type='password' name='cpassword'></p><p> <br /></p><p> New password</p><p> <br /></p><p> <input type='password' name='npassword'> <input type='submit' name='ue' value='Submit'></p><p> </form></p><p> </p><p> </p><p> </p><p> </body></p><p> ";</p><p>}</p><p>[/PHP]</p><p> </p><p>Here is the database structure :</p><p><a href="http://sharefast.net/view/WNowEvkQik8z" target="_blank">http://sharefa.st/view/WNowEvkQik8z</a></p><p> </p><p> </p><p>--</p><p>Hope you like it <img src="/styles/default/xenforo/smilies/emojione/smile.png" class="smilie" loading="lazy" alt=":)" title="Smile :)" data-shortname=":)" /></p><p>Any question about this script , please contact me.</p><p> </p><p>Added the config.php page for easier database configuration.</p></blockquote><p></p>
[QUOTE="Alam, post: 73394, member: 4147"] Hello, Here is a basic & simple PHP script wrote from scratch on my own. The system includes : [LIST] [*]Login page [*]Config page [*]Registration page [*]Md5 encryption [*]Members page [*]Logout page [*]account page (change username & password) [*]Simple database structure. [/LIST] -- Config page : [PHP]<?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "php"; mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname); ?>[/PHP] Index/Login page : [PHP]<?php session_start(); include 'config.php'; $username = mysql_real_escape_string($_POST['username']); $password = $_POST['password']; if(isset($_POST['submit'])) { if(!empty($username)&&!empty($password)) { $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $id1 = mysql_query("SELECT id FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); while ($row = mysql_fetch_array($id1)) { $id = $row['id']; } if($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $user = $row['username']; $pass = $row['password']; } if($username==$user&&md5($password)==$pass) { $_SESSION['user']=$username; $_SESSION['user_id']=$id; header("location: me.php"); } else echo "Your password is incorrect, please try again."; } else echo "The user $username does not exist"; } else echo "Please enter your username and password."; } if($_SESSION['user']) { header("location: me.php"); } else { echo "<html> <head> <title>Login page</title> </head> <body> <form action='index.php' method='POST'> Username : <input type='text' name='username'> Password : <input type='password' name='password'> <input type='submit' name='submit' value='Login'> </form> </body> </html>"; ?> [/PHP] Registration Page : [PHP] <?php include 'config.php'; $username = strip_tags($_POST['username']); $email = strip_tags($_POST['email']); $password = strip_tags($_POST['password']); $repeatpassword = strip_tags($_POST['repeatpassword']); if (isset($_POST['submit'])) { if ($username && $email && $password && $repeatpassword) { if ($password == $repeatpassword) { if (strlen($username) > 30) { echo "Your username can't be longer than 30 characters."; } else { if (strlen($email) < 6) { echo "This email is invalid."; } else { if (strlen($password) > 35 || strlen($password) < 6) { echo "Your password must be between 6 and 35 characters."; } else { $ch = mysql_query("SELECT username FROM users WHERE username='$username'"); $check = mysql_num_rows($ch); if ($check != 0) { echo "The username $username already exists."; } else { $hashpassword = md5($password); $insert = "INSERT INTO users (username,email,password) VALUES ('$username','$email','$hashpassword')"; mysql_query($insert); $_SESSION['user']=$username; $_SESSION['user_id']=$id; header("location: me.php"); } } } } } else echo "Password does not match"; } else echo "Please fill in all the fields"; } ?> <html> <head> <title>Register page</title> </head> <body> <form action="register.php" method="POST"> Username <br /> <input type="text" name="username"> <br /> Email <br /> <input type="text" name="email"> <br /> Password <br /> <input type="password" name="password"> <br /> Repeat password <br /> <input type="password" name="repeatpassword"> <br /> <input type="submit" name="submit" value="Create account"> </form> </body> </html>[/PHP] Me.php page : [PHP]<?php session_start(); if($_SESSION['user']) { echo "<a href='me.php'>". $_SESSION['user'] ."</a> |"; echo " <a href='account.php'>My account </a> |<a href='logout.php'>Logout</a>"; } else echo "You must be logged in to view this page."; ?>[/PHP] Logout page : [PHP]<?php session_start(); session_destroy(); header("location: index.php"); ?>[/PHP] Account page : [PHP] <?php session_start(); $username = strip_tags($_POST['username']); $cpassword = $_POST['cpassword']; $npassword = $_POST['npassword']; mysql_connect("localhost", "root", ""); mysql_select_db("php"); $update = "UPDATE users SET username = '$username' WHERE id = '". $_SESSION['user_id'] ."'"; $check = mysql_query("SELECT username FROM users WHERE username='$username'"); $pwcheck = mysql_query("SELECT password FROM users WHERE username='$username'"); $numrows = mysql_num_rows($check); if (isset($_POST['eu'])) { if ($username) { if ($numrows!=0) { echo "This username already exists!"; } else { mysql_query($update); session_start(); session_destroy(); header("location: logout.php"); } } else echo "Please enter a username"; } else { if(isset($_POST['ue'])) { if ($cpassword&&$npassword) { while($row = mysql_fetch_assoc($pwcheck)) { $dbpass = $row['password']; } $hcpassword = md5($cpassword); $hnpassword = md5($npassword); if ($hcpassword==$dbpass) { if (strlen($npassword)>35 || strlen($npassword)<6) { echo "Your password must be between 6 and 25 characters."; } else { $updatepass = "UPDATE users SET password = '$hnpassword' WHERE id='". $_SESSION['user_id'] ."'"; mysql_query($updatepass); echo "Your password has been changed."; } } else { echo "This is not your current password."; } } else echo "Please field in both fields."; } } if (!$_SESSION['user_id']) { echo "you must be logged in to view this page"; } else { echo "<head> <title>My account</title> </head> <body> <form action='account.php' method='POST'> <h1>Username</h1> <a href='me.php'>Go back</a> Edit username <br /> <input type='text' name='username'> <input type='submit' name='eu' value='Update account'></form> </form> <form action='account.php' method='POST'><br /> <h1>Change password</h1> <input type=\"hidden\" name=\"username\" value=\"". $_SESSION['user'] ."\" /> Current password <br/> <input type='password' name='cpassword'> <br /> New password <br /> <input type='password' name='npassword'> <input type='submit' name='ue' value='Submit'> </form> </body> "; } [/PHP] Here is the database structure : [URL='http://sharefast.net/view/WNowEvkQik8z']http://sharefa.st/view/WNowEvkQik8z[/URL] -- Hope you like it :) Any question about this script , please contact me. Added the config.php page for easier database configuration. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
[PHP] Membership system.
Top