Jump to content

Recommended Posts

I have successfully been authenticating members using sessions:

session_start();
$link = mysql_connect("ositowebsolutions.com","ositoweb","••••••") or die("Could not connect: ".mysql_error());
        mysql_select_db("osito_mysql")or die("Could not select database: ".mysql_error());

  $query = "SELECT * FROM ithf_members WHERE uname = '{$_SERVER['PHP_AUTH_USER']}' and pword = '{$_SERVER['PHP_AUTH_PW']}'";
  $result = mysql_query($query) or die("Could not perform query: ".mysql_error());
$row = mysql_fetch_array($result);
$uname = $row['uname'];
$pword = $row['pword'];
$id = $row['id'];


if (!isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
    || !($_SERVER['PHP_AUTH_USER'] == $uname && $_SERVER['PHP_AUTH_PW'] == $pword))
{
    header('WWW-Authenticate: Basic realm="Authorization Required!"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Required!';
    exit;
}

 

What I would not like to do is, instead of include the code above in every single protected file, I'd like to do it with an include statement: include 'prefix_authenticate.php';

 

However, this gives me an "unexpected } error" at the end of the page, because it never seemed to INCLUDE the prefix file. We use INCLUDE all the time so as to not have to repeat code time and again. Is it not possible for something like this?

Link to comment
https://forums.phpfreaks.com/topic/137975-authentication-using-include/
Share on other sites

Yeah definitely. You still need <?php ?> tags around your included code though, could that be the problem? If you do already, it's just a syntax error - look what line and file it's in either try and fix it or post the surrounding few lines..

 

A

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.