Jump to content

Recommended Posts

Hello,
i Have to create pages with HTTP Authentication for security, i can get the HTTP authentication working with the IE popup box that requests for username and password. but what i am wanting to do is to be able to enter username and password on the index page of my website then login from there instead of using the IE popup box thing.

if anyone could help it would be great

Thanks, Mal

This is the code i have at the min but i don't work
[code]<?php
// ***************************
// *** HTTP AUTHENTICATION ***
// ***************************
{
$customerid = $_POST['customerid'];
$password = $_POST['password'];
}
{
// Connect to the Oracle database

$conn = OCILogon("p950278","password","//127.0.0.1/XE")
or die("<strong>ERROR:</strong> Connection to the Oracle database failed. Please contact the system administrator");

// Validate the user.

$sql = "SELECT * FROM customer WHERE lower(customerid) = lower('{$_SERVER['PHP_AUTH_USER']}') AND lower(password) = lower('{$_SERVER['PHP_AUTH_PW']}')";

// Parse the SQL statement.
$stmt = OCIParse($conn, $sql);


// Execute / run the query.
OCIExecute($stmt);


OCIFetch($stmt);

// If no rows were returned the username and password are invalid.
// Display a message to the user and exit the script.

if (oci_num_rows($stmt) == 0)
{
echo "<h1>Student Record System: Logon Failure</h1>\n";
echo "<p>Either the username or password that was entered was incorrect. \n";
echo "The logon was unsuccessful.</p>\n";
$_SERVER['PHP_AUTH_USER'] = "UNAUTHORISED";
exit;
}
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Uk Holidays</title>
<link href="mystyle.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="datetimepicker.js">
</script>
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-weight: bold;
}
.style5 {color: #FFFFFF; font-weight: bold; font-size: 12px; }
.style6 {
font-size: 12px;
color: #000000;
}
.style8 {font-size: 11px}
-->
</style>
</head>

<body>
<?php
if (!isset($_GET['page']))
{
        $url="index.php?page=home";
header("Location: ".$url);
exit;
}
else
{
$page = $_GET['page'];
}
?>
<?php
$today = date("d-m-y");
?>                       
<table width="800" height="81%"  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="111" rowspan="2"><div align="left"><img src="images/logo.jpg" width="207" height="93"></div></td>
    <td height="63" colspan="5" valign="top" background="images/topbar.jpg">
<form name="form1" method="post" action="">
        <p align="right" class="style6"><br>
          Username:
          <input name="customerid" type="text" id="customerid" size="15">
          Password:
          <input name="password" type="password" id="password" size="15">
          <input name="login" type="submit" id="login" value="Login">
        </p>
    </form></td>
  </tr>
  <tr>
    <td height="18" colspan="5" valign="bottom" background="images/topbar.jpg"><div align="right">
     
    </div></td>
  </tr>
  <tr>
    <td height="18" valign="top">&nbsp;</td>
    <td colspan="5" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td width="255" height="792" rowspan="2" valign="top"><form action="" method="post" name="holsearch" id="holsearch">
        <div align="left">
          <table width="100%" height="385"  border="0" id="holiday">
            <tr>
              <td height="31" colspan="3"><div align="left"><span class="style1"><img src="images/searchtop.jpg" width="100%" height="32"></span></div></td>
            </tr>
            <tr>
              <td bgcolor="#3892C6"><span class="style5">Type</span></td>
              <td colspan="2" bgcolor="#8CBFDE"><select name="type" id="type">
                <option>Cottage</option>
                <option>Boat</option>
              </select></td>
            </tr>
            <tr>
              <td width="35%" bgcolor="#3892C6"><span class="style5">Destination</span></td>
              <td colspan="2" bgcolor="#8CBFDE"><select name="destination" id="destination">
              </select></td>
            </tr>
            <tr>
              <td bgcolor="#3892C6"><span class="style5">Check In </span></td>
              <td width="41%" bgcolor="#8CBFDE"><input type="text" id="startdate" value="<?php echo "$today"?>" size="15"></td>
              <td width="24%" bgcolor="#8CBFDE"><a href="javascript:NewCal('startdate','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>
            </tr>
            <tr>
              <td bgcolor="#3892C6"><span class="style5">Check Out</span></td>
              <td bgcolor="#8CBFDE"><input id="enddate" type="text" size="15"></a></td>
              <td width="24%" bgcolor="#8CBFDE"><a href="javascript:NewCal('enddate','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>
            </tr>
            <tr>
              <td bgcolor="#3892C6"><span class="style5">Rooms</span></td>
              <td colspan="2" bgcolor="#8CBFDE"><select name="rooms" id="rooms">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
              </select></td>
            </tr>
            <tr>
              <td bgcolor="#3892C6"><span class="style5">Adult</span></td>
              <td colspan="2" bgcolor="#8CBFDE"><select name="adult" id="adult">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
                <option value="10">10</option>
              </select></td>
            </tr>
            <tr>
              <td bgcolor="#3892C6"><span class="style5">Children</span></td>
              <td colspan="2" bgcolor="#8CBFDE"><select name="children" id="children">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
                <option value="10">10</option>
              </select></td>
            </tr>
            <tr>
              <td bgcolor="#3892C6"><span class="style5">Price Min</span></td>
              <td colspan="2" bgcolor="#8CBFDE"><span class="style1">
                <select name="min" id="min">
                  <option value="200">&pound;200</option>
                  <option value="300">&pound;300</option>
                  <option value="400">&pound;400</option>
                  <option value="500">&pound;500</option>
                  <option value="600">&pound;600</option>
                  <option value="700">&pound;700</option>
                  <option value="800">&pound;800</option>
                  <option value="900">&pound;900</option>
                  <option value="1000">&pound;1000</option>
                  <option value="1100">&pound;1100</option>
                  <option value="1200">&pound;1200</option>
                </select>
              </span></td>
            </tr>
            <tr>
              <td bgcolor="#3892C6"><span class="style5">Price Max</span></td>
              <td colspan="2" bgcolor="#8CBFDE"><select name="max" id="max">
                <option value="400">&pound;400</option>
                <option value="600">&pound;600</option>
                <option value="800">&pound;800</option>
                <option value="1000">&pound;1000</option>
                <option value="1200">&pound;1200</option>
                <option value="1400">&pound;1400</option>
                <option value="1600">&pound;1600</option>
              </select></td>
            </tr>
            <tr>
              <td colspan="3" bgcolor="#3892C6"><div align="center"><input type="image" name="Send" alt="Send" value="Send" src="images/searchbutton.gif">


</div></td>
            </tr>
            <tr>
              <td height="30" colspan="3"><img src="images/searchbottom.jpg" width="100%" height="32"></td>
            </tr>
          </table>
        </div>
        </form>
    </td>
    <td height="792" colspan="5" valign="top" background="images/topbar.jpg">      <?php
if(file_exists($page.'.php'))
{
  include $page.'.php';
}
else
{
echo "No Page Exists";
}
?>      </td>
  </tr>
  <tr>
    <td width="126" valign="top" background="images/topbar.jpg"><span class="style8">Brochure Request</span></td>
    <td width="119" valign="top" background="images/topbar.jpg"><span class="style8">Help And FAQ </span></td>
    <td width="112" valign="top" background="images/topbar.jpg"><span class="style8">Terms of Use </span></td>
    <td width="98" valign="top" background="images/topbar.jpg"><span class="style8">About Us </span></td>
    <td width="90" valign="top" background="images/topbar.jpg"><span class="style8">Site Map </span></td>
  </tr>
</table>
</body>
</html>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/33584-http-authentication-help/
Share on other sites

i just want to be able to login so i can access the restricted parts of my site and i need to use HTTP Authentication. the index page will not be protected just have the function on to login so the restricted parts of my site can be accessed.
the Popup box is generated by this code:

[code]if (!isset($_SERVER['PHP_AUTH_USER']))
{
// Display the logon dialog box.

header('WWW-Authenticate: Basic realm="CG0119 Student Record System"');
header('HTTP/1.0 401 Unauthorized');

// If the user has clicked the 'cancel' button display appropriate messages and exit

echo "<h1>Student Record System: Logon Failure</h1>\n";
echo "<p><strong>The [Cancel] button was clicked - the logon process has been stopped.</strong></p>\n";
exit;
} else {[/code]

It pops up and you enter username and password

Thanks, Mal
What I thought would be easier is to use a htaccess file, put all the files you want to protect in that folder, and you can actually access it by entering the correct username and password combination just in your url address, so the what the user inputs, simply put it into the url address as a variable:
http://$username:$password@www.website.com/directory/
for more info on that:
http://www.freewebmasterhelp.com/tutorials/htaccess/3

btw, i dont know if this is what you are looking for, but it seems to be a lot simpler than what you are doing....
Ted
I have to use HTTP authentication it is part of the requirments for my assignment for university, i would normally use php sessions so i am trying to use http authentication in the same way as sessions, i know it is possible because i have seen a friends HTTP authentication and it is setup like that, but i can't ask how he done it has it could be classed as copying.


thanks for the help anyway

Mal
Two things...

1. Ted, the http authentication that Mal is using is the same thing as .htaccess, but he's using the header() function in PHP to present it on a per page basis as opposed to a per directory basis.  It just uses the same WWW-Authenticate: Basic (depending on how you have .htaccess setup)

2. Mal, Are you sure your friend has it setup this way?  As far as I was aware, you could log in using that pop-up box that gets presented in the browser and then pass these values to php, but not the other way around.

Regards
Huggie
This thread is more than a year old. Please don't revive it unless you have something important to add.

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

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.