Support Forums
[TUT] PHP Password Protected Page - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: [TUT] PHP Password Protected Page (/showthread.php?tid=8216)

Pages: 1 2 3


RE: [TUT] PHP Password Protected Page - Review - 10-02-2010

This is a very old method, I think it works on iStealer site's.


RE: [TUT] PHP Password Protected Page - Sιℓνєя - 10-02-2010

Hmm thats great, thanks bro kool method. Tongue


RE: [TUT] PHP Password Protected Page - Shirosaki. - 10-03-2010

Good to know, thanks mate, is it yours ?


RE: [TUT] PHP Password Protected Page - Zankza - 10-08-2010

Just what I needed for my GM panel, Thanks for this!


RE: [TUT] PHP Password Protected Page - ariton - 10-08-2010

Thank you very much for this. It will help me alot.


RE: [TUT] PHP Password Protected Page - Zankza - 10-08-2010

Though, it would've been better if it was hashed or something. always be safe, better than nothing.


RE: [TUT] PHP Password Protected Page - SlimDeath - 11-16-2010

Great find mate. Its very useful,i may use in future.


RE: [TUT] PHP Password Protected Page - Chimi - 12-06-2010

Nice work, and good share. Well done!


RE: [TUT] PHP Password Protected Page - NathanE - 12-12-2010

(07-06-2010, 04:01 PM)PurpleHaze Wrote: This login does not use a database so the password is in the code which is "lol". Since it is server sided no one can right-click to view password.

I'll explain how the code works below.

In Section 1 the code uses sessions to determine whether a user is logged in. Our session variable is "$_SESSION['auth']" and we assign to a value of false or 0 which means that the user is not authorized to view the page.

Section 2 checks to see if the form was submited and then if the password is equal to "lol". If the password is equal to "lol" then our variable changes to true or 1.

Section 3 checks to see the variable is equal to 0. If it is equal to 0 then that means that the user has not logged in and so we need to login screen to be shown.

Section 4 checks to see if the variable is equal to 1. If it is then that means that the user is logged in and then is allowed to see the other content and so it is shown.

Remember that this script is basic and many more features could be added including security. This is just so you understand how it works.

Code:
<?php
//Section 1
session_start();

$_SESSION['auth'] = 0;

//Section 2
if (isset($_POST['submit']))
{
    if ($_POST['password'] == "lol")
    {
        $_SESSION['auth'] = 1;
    }
}

//Section 3
if ($_SESSION['auth'] == 0)
{
    echo
    ('
<form method="post">
<input type="password" name="password" />
<input type="submit" name="submit" value="Login" />
</form>
    ');    
}

//Section 4
if ($_SESSION['auth'] == 1)
{
    echo
    ('
<b>This is our secret content. You can use HTML codes here also.</b>
    ');
}
?>

(08-26-2010, 01:45 PM)Proof Wrote: It's better to set a cookie

PHP Code:
setcookie("auth"1,  time()+3600); 

Close browser=destroy session. Use a cookie keeps them logged in that one up there lasts an hour.


Thank you both, very helpful.....



RE: [TUT] PHP Password Protected Page - NathaX - 12-12-2010

Thanks for this, needed it for some time.