Garnet Posted March 28, 2006 Share Posted March 28, 2006 Anyone got any codes on login page that is workable? i need it ~ Link to comment Share on other sites More sharing options...
bd1e0d0 Posted March 28, 2006 Share Posted March 28, 2006 I believe the best way to go is by MySQL and sessions. So I have no clue. Do your homework on those and you should get what you need . Link to comment Share on other sites More sharing options...
DarkElf Posted March 30, 2006 Share Posted March 30, 2006 a very simple example, and not the most secure, but here's a start:page1.php will contain a user name and password form which submits to page2, if you don't know how to do that then you need to go back and read the tutorials. page2.php can look something like this: <?php//start sessionsession_start();//create login variable$_SESSION['login']='no';//get inputted username and password$username = $_POST['username'];$password = $_POST['password'];//check username and password and set login variable if correctif $username == 'DarkElf' {if $password == 'Spoon' $_SESSION['login'] = 'yes'; };?>DOCTYPE....HTML headers.....<body><?php//check login variable and display content accordinglyif $_SESSION['login'] == 'no' echo '<p>Sorry, you are not a recognised user, please go back and try again.</p>';else if $_SESSION['login'] == 'yes' echo '<p>Welcome user..... more page content etc.</p>';?></body></html> The second chunk of php needs to be included on every page of your site which you would like to be password protected. After succesfully signing in the user will be 'logged in' for the duration of the session (i.e. until they close that browser window).Please note that this is an extremely simple example, it only allows for one user and the username and password are hard coded into the php. You'll need to learn some considerably more advanced PHP and preferably a web database such as MySQL before you can start making genuinely useful login scripts. Link to comment Share on other sites More sharing options...
pulpfiction Posted March 30, 2006 Share Posted March 30, 2006 I hope this site will help you a lot..http://www.free2code.net/plugins/articles/read.php?id=99 Link to comment Share on other sites More sharing options...
reportingsjr Posted March 30, 2006 Share Posted March 30, 2006 Darkelf you did this part wrong : //check username and password and set login variable if correctif $username == 'DarkElf' {if $password == 'Spoon' $_SESSION['login'] = 'yes'; };?> Its supposed to be: //check username and password and set login variable if correctif $username == 'DarkElf'{ if ($password == 'Spoon'){ $_SESSION['login'] = 'yes'; };};?> Just so he doesnt do that part wrong.. Link to comment Share on other sites More sharing options...
kvnmck18 Posted October 17, 2006 Share Posted October 17, 2006 I don't think this works. I tried it out to test it and it doesn't.Maybe I messed up? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 17, 2006 Share Posted October 17, 2006 Post your code Link to comment Share on other sites More sharing options...
reportingsjr Posted October 17, 2006 Share Posted October 17, 2006 Wow.. I looked at that and was like, is that really me? I guess I didnt know PHP as well . Here is the corrected full script: ?php//start sessionsession_start();//create login variable$_SESSION['login']='no';//get inputted username and password$username = $_POST['username'];$password = $_POST['password'];//check username and password and set login variable if correctif($username == 'DarkElf'){ if($password == 'Spoon'){ $_SESSION['login'] = 'yes'; }}?>DOCTYPE....HTML headers.....<body><?php//check login variable and display content accordinglyif($_SESSION['login'] == 'no'){ echo '<p>Sorry, you are not a recognised user, please go back and try again.</p>';}elseif($_SESSION['login'] == 'yes'){ echo '<p>Welcome user..... more page content etc.</p>';}?></body></html> enjoi Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now