Jump to content

PHP Password protection


Recommended Posts

HiHow about an expansion of the PHP IF statement section to cover PHP password protection? A simple exampleof how to password protect a page on a website. It is a common request among users and could be fairly usefull as well.Callum

Link to post
Share on other sites

Had a look at that, but it's not exactly begginer friendly and the sheer amount of php on the page is daunting unlike the tutorials on the main site.just my 2c

Link to post
Share on other sites

Right, but understand that password protection is a decently complex subject. The basics are simple - you compare one password with another one and figure out if they match, which is a single if statement and doesn't need to be any more complex than this:

if ($password1 == $password2){  // they match}else{  // they don't match}

The details will match your own situation. Like, where are you getting the passwords from? Is the password being looked up in a database, or in a text file, or is it just a hard-coded master password? What do you want to happen if the password check succeeds or fails? Do you want to use cookies or sessions? All of these are questions that you will need to answer, so a tutorial that covers all of that would be more complex than my thread. The example I posted there has code that gets the password from a database (and also registers users), uses the session to keep track if the person is logged in, it will show error messages if they failed the login, etc. So that's just one example. Whatever else you want to happen on your page is sort of up to you, it's not really part of the scope of a tutorial on an if statement.

Link to post
Share on other sites
Had a look at that, but it's not exactly begginer friendly and the sheer amount of php on the page is daunting unlike the tutorials on the main site.just my 2c
Just go through it little by little and understand one thing at a time... this has to be the best tutorial I've seen for beginners. I wish it were around a year or 2 ago!
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...