ilikephp Posted November 14, 2008 Share Posted November 14, 2008 Hello!! In my website, I need to create a php form that contains username and passwords, so the users can sign up automatically and they get their own username and password, How can I do it plz? and how can I make a link to the database so it will check if the username is taken or not and it can display all the username and passwords. Thanks in advance!! Link to comment https://forums.phpfreaks.com/topic/132764-username-and-password/ Share on other sites More sharing options...
aeonsky Posted November 14, 2008 Share Posted November 14, 2008 I created a flat-file db login system if you'd like to modify it for your needs. INDEX.PHP <?PHP include("main.php"); $login->secure(); echo "You are in the member zone!<br /><a href=\"logout.php\">Logout!</a>"; ?> MAIN.PHP <?PHP session_start(); include("loginclass.php"); $login = new login(); ?> LOGINCLASS.PHP <?PHP class login { public function checklogin() { $detailsarray = $this->getdetails(); if ($_POST['username'] == $detailsarray[0] && md5($_POST['password']) == $detailsarray[1]) {$this->grant_session(); return true;} } public function is_submit() { if ($_POST['submit']) return true; } public function is_session() { if ($_SESSION['login']) return true; } public function getdetails() { $details = file_get_contents("details.php"); $both = explode(":", $details); return $both; } public function grant_session() { $_SESSION['login'] = true; } public function logout() { session_destroy(); } public function redirect() { header("Location: {$_SESSION['FROM']}"); } public function saveref() { $_SESSION['FROM'] = $_SERVER['PHP_SELF']; } public function showform() { print ' <form action="'.$_SESSION['FROM'].'" method="post"> <input type="text" name="username"><br /> <input type="password" name="password"><br /> <input type="submit" name="submit"> </form>'; } public function secure() { $this->saveref(); if (!$this->is_session()) { if ($this->is_submit()) { if ($this->checklogin()) $this->redirect(); else echo "Wrong username/password!"; } else $this->showform(); die; } } } ?> LOGOUT.PHP <?PHP include("main.php"); $login->logout(); $login->redirect(); ?> DETAILS.PHP admin:21232f297a57a5a743894a0e4a801fc3 //admin:admin It will be pretty easy for this point. Link to comment https://forums.phpfreaks.com/topic/132764-username-and-password/#findComment-690442 Share on other sites More sharing options...
ilikephp Posted November 14, 2008 Author Share Posted November 14, 2008 Thanks for helping me!! I created all the scripts but in the details.php I left it empty. So when I put the username and password and I got: Wrong username/password! So till now I think everything is OK. So the second step, how can I create a username and password? Thanks!! Link to comment https://forums.phpfreaks.com/topic/132764-username-and-password/#findComment-690449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.