freelancer Posted June 8, 2007 Share Posted June 8, 2007 Well, I have been working out user management system which allows users to register on my clan website, also I'm using 1 php news script with what I add news to my main site and it has also commenting feature which doesn't need registration but I want that only people who has logged in can post comments. How should login script look like that only logged in people are allowed to see $comments area. News script is phpnews (http://newsphp.sourceforge.net) and its template based that where I type $comments it shows comments form. Maybe you guys can give some advices or any user management system which can be integrated with websites. Hope you understood what I mean! Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/ Share on other sites More sharing options...
rusbb Posted June 8, 2007 Share Posted June 8, 2007 i think it might be way easier for you to use some kind of CMS (Content Management System) there are a lot of free ones around: Joomla, Koobi, PHP-Nuke, e107, just to mention some of the most popular ones. They have everything you need - user registrations, news posting, comments only for users etc and much much more. Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270610 Share on other sites More sharing options...
freelancer Posted June 8, 2007 Author Share Posted June 8, 2007 Huh, I'm sure that I can't attach my own created web desing to any of these systems. My website www.team-kommando.com Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270611 Share on other sites More sharing options...
rusbb Posted June 8, 2007 Share Posted June 8, 2007 ah, i didnt realise you had such a complex site. if it was something small it would have been much easier to migrate into a CMS, but i can see that it would be difficult for you. Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270612 Share on other sites More sharing options...
rusbb Posted June 8, 2007 Share Posted June 8, 2007 you can try this: http://www.evolt.org/PHP-Login-System-with-Admin-Features its a PHP Login System with Admin Features Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270615 Share on other sites More sharing options...
freelancer Posted June 8, 2007 Author Share Posted June 8, 2007 you can try this: http://www.evolt.org/PHP-Login-System-with-Admin-Features its a PHP Login System with Admin Features I already worked on it but this code is very complicated and not easy to edit as I would like, but I still keep working on it Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270616 Share on other sites More sharing options...
rusbb Posted June 8, 2007 Share Posted June 8, 2007 there is this: http://www.phptoys.com/e107_plugins/content/content.php?content.34 which is a micro-login system, which stores the user info in a file rather than a MySQL database and it seems to be quite simple, however there is an issue with storage of info in a flat file do you want it to use mysql db? Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270619 Share on other sites More sharing options...
freelancer Posted June 8, 2007 Author Share Posted June 8, 2007 I have been working with mysql alot and I would like it as database more than files. Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270621 Share on other sites More sharing options...
rusbb Posted June 8, 2007 Share Posted June 8, 2007 top 50 user management systems, dont know if that would be of any help http://www.programsdb.com/scriptscategory/10/98/1/0.html sorry i cant be more helpful Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270624 Share on other sites More sharing options...
brissy_matty Posted June 8, 2007 Share Posted June 8, 2007 I generally use MYSQL and cookies -- You need a login form function - a database to store this info into and then the files which do all the work for you. Normally i have a functions file which will contain the Login form and if a user isnt logged in you display the login form - if a user is logged in then you display the content a logged in member would see. This can also be done with mutiple user levels see different content etc. The files you would need (named whatever you like): * Functions - contains a set of functions you can call like login form, forgotten password etc etc * Login - the script which processes the login - user checking - form completeness etc * loggedin - the login form is sent to here and sets cookies etc but only if the login form is valid *usercheck - can be included anywhere you want a check to be made where logged in content should be displayed. - If the user is logged in it will display relevant content if they arent it will say "Need to be logged in" in the area it is included. you would also need to create a registration form, maybe a validation form, and maybe a lost password form. It can become a bit of a headache. then you need if's buts and maybes Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270671 Share on other sites More sharing options...
freelancer Posted June 8, 2007 Author Share Posted June 8, 2007 Sure I know that, but I'm not very good at writing clear, correct and secured code so I would better ask for well-prepared code which I could edit as I like. Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270674 Share on other sites More sharing options...
brissy_matty Posted June 8, 2007 Share Posted June 8, 2007 Possibly not the best code in the world but here you go: login.php <?php //Database/Mysql// $dusername = "mysite_username"; //username to connect to database $dpwd = "mysite_password"; //password to accecss mySQL $dhost = "localhost"; //your db host usually localhost $dbname = "mysite_database_1"; //db name to be accessed $conn = mysql_connect("$dhost","$dusername","$dpwd") or die ("Unable to connect to database."); $db=mysql_select_db($dbname,$conn) or die("Unable to connect to database!"); include("functions.php"); if($action==login) { if($_COOKIE[username]=="" AND $_COOKIE[password]=="") { $md5_password = md5($_POST[password]); $sql = mysql_query("SELECT * FROM users WHERE username = '$_POST[username]' AND password = '$md5_password'") OR DIE("Sorry there is a mysql error."); $row = mysql_fetch_array($sql); $numrows = mysql_num_rows($sql); if($_POST[password]=="") { //include("$sitepath/html/header.php"); print("No password Entered."); login_form(); print("<BR><BR> Lost Password?"); lostpass_form(); //include("$sitepath/html/footer.php"); exit; } elseif($_POST[username]=="") { //include("$sitepath/html/header.php"); print("No username Entered."); login_form(); print("<BR><BR> Lost Password?"); lostpass_form(); //include("$sitepath/html/footer.php"); exit; } elseif($numrows == "0") { //include("$sitepath/html/header.php"); print("Username and Password doesnt match!"); login_form(); print("<BR><BR> Lost Password?"); lostpass_form(); //include("$sitepath/html/footer.php"); exit; } else { setcookie("username","$_POST[username]",time()+30000000); setcookie("password","$md5_password",time()+30000000); echo "<meta http-equiv=refresh content=\"2;url=$siteurl/loggedin.php\">"; //include("$sitepath/html/header.php"); print("your now being logged in!"); //include("$sitepath/html/footer.php"); } } else { //include("$sitepath/html/header.php"); print("Your are already loggedin!"); //include("$sitepath/html/footer.php"); } } if($action=="") { //include("$sitepath/html/header.php"); login_form(); print("<BR><BR> Lost Password?"); lostpass_form(); //include("$sitepath/html/footer.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270739 Share on other sites More sharing options...
brissy_matty Posted June 8, 2007 Share Posted June 8, 2007 functions.php <?php function lostpass_form() { global $siteurl,$sitetitle; print(" <form name='form1' method='post' action='$siteurl/lostpw.php?action=lostpass' name='lp_form' onSubmit=\"document.lp_form.lp_submit.disabled=true\"> <table width='100%' border='0' cellspacing='0' cellpadding='4' align='center'> <tr> <td>Email Address</td> <td><input name='email_address' type='text'></td> </tr> <tr> <td> </td> <td><input name='recover' type='hidden' value='recover'> <input type='submit' name='lp_submit' value='Gain The Knowledge Of My Password!'></td> </tr> </table> </form> "); } function login_form() { global $siteurl,$sitetitle,$username; print(" <form action='$siteurl/login.php?action=login' method='post' name='l_form' onSubmit=\"document.l_form.l_submit.disabled=true\"> <table width='50%' border='0' align='center' cellpadding='4' cellspacing='0'> <tr> <td width='22%'>Username</td> <td width='78%'><input name='username' type='text'></td> </tr> <tr> <td>Password</td> <td><input name='password' type='password'></td> </tr> <tr> <td> </td> <td><input type='submit' name='l_submit' value='Login To Mysite!'></td> </tr> </table> </form> "); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270740 Share on other sites More sharing options...
brissy_matty Posted June 8, 2007 Share Posted June 8, 2007 loggedin.php <?php include("config.php"); include("$sitepath/html/header.php"); include("user_check.php"); // I normally insert a refresf here if i dont wany to display anything print("Your now logged in fully.<BR><BR>"); include("$sitepath/html/footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270742 Share on other sites More sharing options...
brissy_matty Posted June 8, 2007 Share Posted June 8, 2007 user_check.php <?php include_once("$sitepath/functions.php"); $sql = mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[username]'") OR DIE("Sorry Theres a mysql error."); $row = mysql_fetch_array($sql); $num = mysql_num_rows($sql); //check if username exsists if($num == 0) { print("You must be logged in to veiw this page!<BR>"); login_form(); print("<BR>Lost password?"); lostpass_form(); include("$sitepath/html/footer.php"); exit; } //check cookies exsist elseif($_COOKIE[username]=="" OR $_COOKIE[password]=="") { print("You must be logged in to veiw this page!<BR>"); login_form(); print("<BR>Lost password?"); lostpass_form(); include("$sitepath/html/footer.php"); exit; } //check if password is correct elseif($_COOKIE[password] != $row[password]) { print("You must be logged in to veiw this page!<BR>"); login_form(); print("<BR>Lost password?"); lostpass_form(); include("$sitepath/html/footer.php"); exit; } $username = $_COOKIE[username]; $date = date("U"); $updatelastlogin = mysql_query("UPDATE users SET last_login = '$date' WHERE username = '$_COOKIE[username]'"); $pm = mysql_query("SELECT * FROM im WHERE sentto = '$username' AND status = 'unread'"); $npms = mysql_num_rows($pm); if($npms > 0) { print("<table class='all' width=500><tr><td><a href='$siteurl/pm/index.php'>You Have $npms New Message(s)</a></td></tr></table><BR>"); } ?> Like i said - maybe not the best code but with a little playing around i am sure you can achieve what you want. Some of this stuff won't be relevant to your usage - you will just need to remove things that arent like included headers / footers / nav and any irrelevant database fields. Cheers Matt Quote Link to comment https://forums.phpfreaks.com/topic/54719-login-system/#findComment-270745 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.