OK, to cut a long story short. I am trying to make a login system and am having troubles. I can make it so it logs in fine, but, here is the problem:
Say a user logs in and their protected page is called client1.php. Now, when they login to access their page, if they type other secret pages filenames into their browser, they can access them with their login info. So, if client1 accessed his page (client1.php), he could also access client2's page by typing the exact filename lets say client2.php) into the browser. Now, I know there has to be a way of stopping this from happening!
I think it can be done with sessions, but am not sure how. This is the code I have so far:
login.php:
And for will.php (with "will" being what is in the "name" field for). Note: This is what I placed at the top of the page before the HTML, there is the HTML code for the page below it.
So, where have I gone wrong and how do I achieve what I am trying to do. I brought this thread over from WebDesignForums.net:
http://www.webdesignforums.net/showthread.php?p=162336#post162336
So, I dunno if any of the info in that thread helps you. I brought it over to Namepros coz there are a lot more people that come online so a higher chance of quick replies.
Thanks in advance, hope you understand my question.
Will.
Say a user logs in and their protected page is called client1.php. Now, when they login to access their page, if they type other secret pages filenames into their browser, they can access them with their login info. So, if client1 accessed his page (client1.php), he could also access client2's page by typing the exact filename lets say client2.php) into the browser. Now, I know there has to be a way of stopping this from happening!
I think it can be done with sessions, but am not sure how. This is the code I have so far:
login.php:
PHP:
//Connect to database
$dbh=mysql_connect ("BLANK", "BLANK", "BLANK") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("BLANK");
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM users where username='$username' and password='$password'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 1)
{
header("Location: notfound.html");
}
else
{
session_start();
$_SESSION['auth'] = ("$lastName");
header("Location: $lastName.php");
}
?>
And for will.php (with "will" being what is in the "name" field for). Note: This is what I placed at the top of the page before the HTML, there is the HTML code for the page below it.
PHP:
<?php
session_start();
if ($_SESSION['auth']!='will')
{
header("Location: notfound.html");
}
?>
So, where have I gone wrong and how do I achieve what I am trying to do. I brought this thread over from WebDesignForums.net:
http://www.webdesignforums.net/showthread.php?p=162336#post162336
So, I dunno if any of the info in that thread helps you. I brought it over to Namepros coz there are a lot more people that come online so a higher chance of quick replies.
Thanks in advance, hope you understand my question.
Will.
Last edited:
















