rgb192
asked on
object oriented code to protect one php page without editing that page
<?php // RAY_temp_rgb192.php 2013-10-10
error_reporting(E_ALL);
// ONE PAGE WITH LOG-IN REQUIRED
// http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28263785.html
// SESSION CONTROLS AUTHORIZATION DATA
session_start();
// THE AUTHENTICATION CREDENTIALS
$uid = 'rgb192';
$pwd = 'secret';
// IF THE AUTHORIZATION FORM HAS BEEN POSTED
if (!empty($_POST))
{
// TEST BOTH UID AND PWD
if ($_POST['uid'] == $uid)
{
if ($_POST['pwd'] == $pwd)
{
$_SESSION['authorized'] = $uid;
}
}
}
// IF THE CLIENT IS NOT AUTHORIZED, PUT UP THE LOGIN FORM
if (!isset($_SESSION['authorized']))
{
$form = <<<EOD
Please Login:
<form method="post">
<input name="uid" placeholder="User Id" />
<input name="pwd" placeholder="Password" />
<input type="submit" />
</form>
EOD;
echo $form;
}
// IF THE CLIENT IS AUTHORIZED, SHOW THE WEB PAGE
else
{
echo "<h1>Welcome $uid</h1>" . PHP_EOL;
echo "<p>You successfully entered the User Id and Password, so now you can see this page.</p>" . PHP_EOL;
}
I am looking for a login with hardcoded php password
only for one php page
is there a way to modify this code or create a new requirement of an object oriented class
so I can learn more about object oriented php and make the code reusable so I can use with the one page I want to password protect without editing the page I want to protect
Not sure I'm following you - are you trying to separate the username/password from the code above and have it in a separate class?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks