Hi there,
I am trying to password a searchable website which has php pages. I used the following tutorial for login/password code:
http://php.codenewbie.com/articles/php/1482/Login_With_Sessions-Page_1.html
This is the login page:
<?
// Login & Session example by sde
// auth.php
// start session
session_start();
// convert username and password from _POST or _SESSION
if($_POST){
$_SESSION['username']=$_POST["username"];
$_SESSION['password']=$_POST["password"];
}
// query for a user/pass match
$result=mysql_query("select * from users
where username='" . $_SESSION['username'] . "' and password='" . $_SESSION['password'] . "'");
// retrieve number of rows resulted
$num=mysql_num_rows($result);
// print login form and exit if failed.
if($num < 1){
echo "You are not authenticated. Please login.<br><br>
<form method=POST action=index.php>
username: <input type=text name=\"username\">
password: <input type=password name=\"password\">
<input type=submit>
</form>";
exit;
}
?>
And this is a sample page:
<?
// Login & Session example by sde
// link_1.php
// connect to database
include("inc/connect.php");
// include auth and nav
include("inc/auth.php");
// begin content
include("inc/nav.php");
echo "This is my Link 1.";
// close mysql connection
mysql_close();
?>
For my page to be password protected it has to go within the echo""; but I cannot put php code here, therefore I can't password protect my php pages with this code.
Any suggestions of how to get around this?
Many thanks
Wendy