Jump to content

Password protected area


Recommended Posts

I would love to have a page on my new website, where my friends only (or anyone I will give password to) can log in to see pages no one else will be able to see. Would it be also possible to direct them to different files depending on what username/password they supplied? Not such a fan of putting pictures etc publicly accessible on the web (do not everyone want to see my spotty face;-)). Can this be done in simple way without use of databases etc?Kurt

Link to post
Share on other sites

Well, you can try .htaccess and .htpasswd files to pretect folders.with PHP you can't protect images, but you can protect the page itself something like this:

<?phpif($_POST['user'] == "username" && $_POST['password'] == "password") {?><!-- Show some HTML of the site --><?php} else {?><form action="?a=1" method="post"><div>Log in to view this page:<br />Username: <input type="text" name="user" /><br />Password: <input type="password" name="password" /><br /><input type="Submit" /></div></form><?php}?>

Link to post
Share on other sites

This is a lazy thing you could try, I'm bored and you probably won't do this but you could have an invisible link that doesn't show the URL in the bottom left part of the browser and if clicked it will load JavaScript on the page for whatever. Definately not safe-proof or whatever but thats an idea. Don't use that idea. Not safe and wont accomplish what you want. I don't even know why I posted here...

Link to post
Share on other sites
with PHP you can't protect images
Well, you could make the image a PHP file that sets its MIME type to image/whatever then echoes the image data onto the screen, but first checks for a session variable or something (don't know what encoding the image has to be in though)...
<?phpsession_start();header("Content-Type: image/gif");if (isset($_SESSION['logged_in'])) {echo /*Whatever the image's code is*/;} else {echo /*An image saying "can't access" or whatever*/;}?>

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...