cjc1055
08-17-2005, 09:14 PM
Ok, I am trying to create a way to securely log into my site then view certain pages that are only viewable when you are logged in. Even if you knew that the secure page was page2000.php, if you type it in it should deny you access unless you log in.
Here is what I have so far. I have created the database in mysql and have added a username and password to use.
I have created the login form:
<form action="validate.php" method="post">
<input type="text" maxlength="10" name="username">
<input type="password" maxlength="10" name="password">
<input type="submit" name="submit" value="Submit">
</form>
and I have created the validate.php (validates the login) and it works perfectly, so thats done, now how do i get it to redirect to the secure pages and keep those pages secure?
Here is the code for the validate.php, this should look familar :)
<?php session_start();
include 'config.php';
include 'connect.php';
$_SESSION['logged'] = 0;
if (isset($_POST['submit'])) {
$sql = "SELECT * FROM `cflpass` WHERE `username` = '". $_POST['username'] ."'";
$sql = mysql_query($sql);
$result = mysql_fetch_assoc($sql);
if($_POST['username'] == $result['username'] &&
$_POST['password'] == $result['password']) {
$_SESSION['user'] = $result['id'];
$_SESSION['logged'] = 1;
print 'login success';
}
else {
print ' Login Failed';
}
}
?>
Here is what I have so far. I have created the database in mysql and have added a username and password to use.
I have created the login form:
<form action="validate.php" method="post">
<input type="text" maxlength="10" name="username">
<input type="password" maxlength="10" name="password">
<input type="submit" name="submit" value="Submit">
</form>
and I have created the validate.php (validates the login) and it works perfectly, so thats done, now how do i get it to redirect to the secure pages and keep those pages secure?
Here is the code for the validate.php, this should look familar :)
<?php session_start();
include 'config.php';
include 'connect.php';
$_SESSION['logged'] = 0;
if (isset($_POST['submit'])) {
$sql = "SELECT * FROM `cflpass` WHERE `username` = '". $_POST['username'] ."'";
$sql = mysql_query($sql);
$result = mysql_fetch_assoc($sql);
if($_POST['username'] == $result['username'] &&
$_POST['password'] == $result['password']) {
$_SESSION['user'] = $result['id'];
$_SESSION['logged'] = 1;
print 'login success';
}
else {
print ' Login Failed';
}
}
?>