Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
PHP Help
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Weasel" data-source="post: 170452" data-attributes="member: 9520"><p>Make a new file security.php, and add:</p><p>[PHP]<?php</p><p>session_start();</p><p> </p><p>$sUsername = "admin"; // Your username</p><p>$sPassword = "password"; // Your password</p><p> </p><p>if (!isset($_SESSION['logged_in']))</p><p>{</p><p> echo '<h1>Login</h1>';</p><p> if ($_SERVER['REQUEST_METHOD'] == 'POST')</p><p> {</p><p> if (empty($_POST['username']) || empty($_POST['password']))</p><p> {</p><p> echo '<span style="color:red; font-weight: bold">Please fill in all fields!</span>';</p><p> }</p><p> elseif ($_POST['username'] != $sUsername || $_POST['password'] != $sPassword)</p><p> {</p><p> echo '<span style="color:red; font-weight: bold">Your username/password is wrong!</span>';</p><p> }</p><p> else</p><p> {</p><p> header("Refresh: 1");</p><p> $_SESSION['ingelogd'] = true;</p><p> echo '<span style="color:green; font-weight: bold">You are now logged in!</span>';</p><p> }</p><p> }</p><p> else</p><p> {</p><p> exit('You need to log-in to view this page.<br /><br /></p><p> <form method="POST" action=""><p></p><p> Username:<br /></p><p> <input type="text" name="username" /><br /><br /></p><p> Password:<br /></p><p> <input type="password" name="password" /><br /><br /></p><p> <input type="submit" value="Login" /> <input type="reset" value="Empty fields" /></p><p> </form>');</p><p> }</p><p>}</p><p>?>[/PHP]</p><p> </p><p>Now every page you want to secure, add the following on top of that page:</p><p>[PHP]<?php</p><p>include("security.php");</p><p>?>[/PHP]</p><p> </p><p>And if you want a logout page, make logout.php and add:</p><p>[PHP]<?php</p><p>unset($_SESSION['logged_in']);</p><p>session_destroy();</p><p>echo "You have succesfully logged out.";</p><p>header ("Refresh: 5; index.php");</p><p>?>[/PHP]</p><p> </p><p>And add a link to the logout page in your layout:</p><p>[CODE]<a href="logout.php">Log out</a>[/CODE]</p></blockquote><p></p>
[QUOTE="Weasel, post: 170452, member: 9520"] Make a new file security.php, and add: [PHP]<?php session_start(); $sUsername = "admin"; // Your username $sPassword = "password"; // Your password if (!isset($_SESSION['logged_in'])) { echo '<h1>Login</h1>'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (empty($_POST['username']) || empty($_POST['password'])) { echo '<span style="color:red; font-weight: bold">Please fill in all fields!</span>'; } elseif ($_POST['username'] != $sUsername || $_POST['password'] != $sPassword) { echo '<span style="color:red; font-weight: bold">Your username/password is wrong!</span>'; } else { header("Refresh: 1"); $_SESSION['ingelogd'] = true; echo '<span style="color:green; font-weight: bold">You are now logged in!</span>'; } } else { exit('You need to log-in to view this page.<br /><br /> <form method="POST" action=""><p> Username:<br /> <input type="text" name="username" /><br /><br /> Password:<br /> <input type="password" name="password" /><br /><br /> <input type="submit" value="Login" /> <input type="reset" value="Empty fields" /> </form>'); } } ?>[/PHP] Now every page you want to secure, add the following on top of that page: [PHP]<?php include("security.php"); ?>[/PHP] And if you want a logout page, make logout.php and add: [PHP]<?php unset($_SESSION['logged_in']); session_destroy(); echo "You have succesfully logged out."; header ("Refresh: 5; index.php"); ?>[/PHP] And add a link to the logout page in your layout: [CODE]<a href="logout.php">Log out</a>[/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
PHP Help
Top