Fruddy Posted August 7, 2006 Author Share Posted August 7, 2006 yea, it does:http://www.my-project.dk/test.phpLogin.php:[code]<?phpif ($login_match == 1) { $_SESSION['username'] = $username; echo "du er logget ind som " ; echo $username;}else{if (($message == "login_info") || ($message == "userinfo")) { if ($message == "login_info") { echo "Du har ikke skrevet dit brugernavn eller kodeord"; } if ($message == "userinfo") { echo "dit brugernavn og kodeord matcher ikke sammen"; }} }?><form action="checkuser.php" method="post" name="form1"> <div align="justify"> <table border="0" align="center"> <tr> <td class="t11_grey">Brugernavn:</td></tr><tr> <td><input name="username" type="text" id="username"></td> </tr><br> <tr> <td class="t11_grey"><br>Kodeord</td></tr><tr> <td><input name="password" type="password" id="password"></td> </tr> <tr> <td><input type="submit" name="Submit" value="Submit"> <a href="http://www.my-project.dk/register.php"> <u>opret bruger</u></a></td> </td> </table> </div></form> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/16427-php-membership-system-problem/page/3/#findComment-70532 Share on other sites More sharing options...
tomfmason Posted August 7, 2006 Share Posted August 7, 2006 I'm sorry when I said to add that to your login script I meant the checkuser.phplike this[code]<?phpsession_start(); include ('db.php');array_pop($_POST); if ( get_magic_quotes_gpc() ) { $_POST= array_map('stripslashes', $_POST); }$username= mysql_real_escape_string(trim($_POST['username'])); $password= mysql_real_escape_string(trim($_POST['password']));$mdpwd= md5($password);if ((!$username) || (!$password)) { $message = "login_info"; include("login.php"); exit();} $sql= sprintf("SELECT COUNT(*) AS login_match FROM `users` WHERE `username` = '%s' AND `password`= '%s'", $username, $mdpwd); $res= mysql_query($sql) or die(mysql_error()); $login_match= mysql_result($res, 0, 'login_match'); if ( $login_match == 1 ) { $_SESSION['username']= "$username"; include("somepage.php");} else { $message = "userinfo"; include("login.php"); exit(); }?>[/code]I would change the login.php back to what it was. Quote Link to comment https://forums.phpfreaks.com/topic/16427-php-membership-system-problem/page/3/#findComment-70538 Share on other sites More sharing options...
Fruddy Posted August 7, 2006 Author Share Posted August 7, 2006 Well i think i have to change the login.php, because in the index, when i login the login.php apear, but i dont want it to apear, when im logged in.But i want to have the "you are now logged in as $username"" to appear, instead of the login.php Quote Link to comment https://forums.phpfreaks.com/topic/16427-php-membership-system-problem/page/3/#findComment-70554 Share on other sites More sharing options...
tomfmason Posted August 7, 2006 Share Posted August 7, 2006 are you pasting this exact code at the top of the protected file.[code=php:0]session_start();if (!$_SESSION['username']) { echo "You must login to view this page"; include("login.php"); exit(1);} echo "You are logged in as <b>" . $_SESSION['username'] . " </b>";[/code]If you used that checkuser.php that I posted with this ^ piece of code at the begining of the protected file. Then you should have no trouble. Quote Link to comment https://forums.phpfreaks.com/topic/16427-php-membership-system-problem/page/3/#findComment-70559 Share on other sites More sharing options...
Fruddy Posted August 7, 2006 Author Share Posted August 7, 2006 all pople can view all sites, i just want to make sure that i am logged in.My checkuser:[code]<?phpsession_start(); include ('database.php');array_pop($_POST); if ( get_magic_quotes_gpc() ) { $_POST= array_map('stripslashes', $_POST); }$username= mysql_real_escape_string(trim($_POST['username'])); $password= mysql_real_escape_string(trim($_POST['password']));$mdpwd= md5($password);if ((!$username) || (!$password)) { $message = "login_info"; include("login.php"); exit();} $sql= sprintf("SELECT COUNT(*) AS login_match FROM `users` WHERE `username` = '%s' AND `password`= '%s'", $username, $mdpwd); $res= mysql_query($sql) or die(mysql_error()); $login_match= mysql_result($res, 0, 'login_match'); if ( $login_match == 1 ) { $_SESSION['username']= "$username"; echo "Du er nu logget ind som<b> "; echo $username; echo "</b>";} else { $message = "userinfo"; include("login.php"); exit(); }?>[/code]The login bar: [code] <?php session_start();if (!$_SESSION['username']) { include ("login.php"); exit(1);}else {echo "Du er logget ind som <b>" . $_SESSION['username'] . " </b>";} ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16427-php-membership-system-problem/page/3/#findComment-70575 Share on other sites More sharing options...
tomfmason Posted August 7, 2006 Share Posted August 7, 2006 Ok now in your checkuser.php change this [code=php:0]if ( $login_match == 1 ) { $_SESSION['username']= "$username"; echo "Du er nu logget ind som<b> "; echo $username; echo "</b>";} else { $message = "userinfo"; include("login.php"); exit(); }?>[/code][b]To this[/b][code=php:0]if ( $login_match == 1 ) { $_SESSION['username']= "$username"; echo "Du er nu logget ind som<b> "; include("some_protected_page.php");//this is were you want people to go after login echo "</b>";} else { $message = "userinfo"; include("login.php"); exit(); }[/code]Now say you have a file called some_protected_page.php You would do this.[code]<?phpsession_start();if (!$_SESSION['username']) { echo "You must login to view this page"; include("login.php"); exit(1);}?><!---html goes below here---><html><head><title>Some Protected Page</title></head><body><p> <?php echo 'Hello <b> ' . $_SESSION['username'] . '</b> you are now viewing a protected page.'; ?></p></body></html>[/code]Give this a try and you will see the proper use Quote Link to comment https://forums.phpfreaks.com/topic/16427-php-membership-system-problem/page/3/#findComment-70582 Share on other sites More sharing options...
trulu Posted November 25, 2006 Share Posted November 25, 2006 hmmm can you send me all the working php page from the membership system tutorial T_T or copy all the php script in here plzzz.... Quote Link to comment https://forums.phpfreaks.com/topic/16427-php-membership-system-problem/page/3/#findComment-129930 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.