jandrews3 Posted December 22, 2008 Share Posted December 22, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/137975-authentication-using-include/ Share on other sites More sharing options...
genericnumber1 Posted December 22, 2008 Share Posted December 22, 2008 You shouldn't have any problem throwing the code you listed into a separate file and require()ing it on another page... could you give us some more info or an example? Quote Link to comment https://forums.phpfreaks.com/topic/137975-authentication-using-include/#findComment-721234 Share on other sites More sharing options...
Adam Posted December 22, 2008 Share Posted December 22, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/137975-authentication-using-include/#findComment-721239 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.