Jump to content

How To Create A Password Protected Page?


ndelc

Recommended Posts

There are several ways to do that. If you want to have users be able to register and login with usernames and passwords stored in a database, check here:http://w3schools.invisionzone.com/index.php?showtopic=12509If you just want a page that only you can access, where you don't care about adding new users, it can be a lot simpler. But still read through that thread for the form processing parts, if you don't know how to process a form with PHP you need to do that first.

Link to comment
Share on other sites

I was reading that post and found this:

Ideally, you should have all of your PHP code on the top of your file only, and all HTML code after that. All PHP processing should be finished by the time you start sending output to the browser.
This is something that I'm trying to do, but is there a way to specify to PHP *where* to write the stuff I want?Right now I'm doing a multiple style script, that depending on the style chosen it'd write header, menu, body, etc (these are self contained php pages that'll write whatever's in my XML file) in the order I'd write them to be.But for this I'm having to write alot (and I mean *alot*) inside the HTML's body, is there any problem or better way to do this?
Link to comment
Share on other sites

There's a better way to do it, but it's a lot more complex. It's easy to just stick some PHP code in the middle of your HTML and write out whatever you want. You can also have all your processing code on the top, and save all your info into variables, and then in the HTML just print out whichever variable wherever you want it. If you want more separation than that, then you probably need to use a template system. With a template system you would create page templates with special tags that the template processor fills in, so your PHP code generates the data you need for the page, then sends the data to the template engine and tells it which template to use. That way you have no HTML code in the PHP file at all, it's all in the template, but it's a lot more complex.

Link to comment
Share on other sites

  • 2 weeks later...

Any Javascript method is very insecure, I completely discourage it.

Pros can infiltrate such sites with these forms of protection.
That refers to people like me (and a lot of people who know less than me).
Link to comment
Share on other sites

Can anyone point me to a good tutorial on how to create a password protected web page?Thanks!
I think the simplest way is this one:
If (isset($_SESSION[“username”])){	//show webpage }Else{	Echo “Access denied. Please login”;}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...