Hello,
I am writing a script that will let users to do the database functions (insert, delete and so on....). There are around 50 - 100 users. It is possible that there can be more than one users at a time accessing and doing their stuff with the database.
How it is possible to differentiate between two users if they are entering the data at the same time? Will only SESSIONS do the trick or do I need to know something else too?
If SESSIONS can only do the job then can you please see my script?
index.php
<?php
header("Location: login.php");
exit;
?>
login.php
<form name="entryform" method="post" action="authorize.php">
<div class="fond">
<table align="center">
<tbody>
<tr><td> </td></tr>
<tr>
<td>Username:</td>
<td><input type="text" name="username" maxlength="10" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" maxlength="10" /></td>
</tr>
<tr><td> </td></tr>
<tr>
<td><input type="hidden" name="verify_authorize" value="ok" /></td><td align="right"><input type="submit" value="Login" /></td>
</tr>
<tr><td> </td></tr>
</tbody>
</table>
</div>
</form>
authorize.php
<?php
if ($_POST['verify_authorize']=="ok") {
session_start();
session_register("SESSION");
require ('application.php');
$result = mysql_query("SELECT COUNT(*) FROM users WHERE username='$username' AND password='$result_password'");
// COUNT because you don't need the actual data in the row, just whether there
// is a row there or not.
$result_count = mysql_result($result,0,0);
if($result_count>0) // A successful match against a database record.
{
$SESSION["user"] = $username;
$SESSION["ip"] = $REMOTE_ADDR;
$SESSION["time"] = time();
echo "
<table border=\"0\" align =\"center\">
<tbody>
<tr>
<td>You are authorized.</td>
</tr>
<tr>
<td>
<form action=\"users.php\" method=\"post\" />
<input type=\"text\" name=\"senduser\" value=\"$username\" />
<input type=\"submit\" value=\"Login\" />
<script language=\"text/javascript\"></script>
</td></tr></tbody></table>
</body>
</html> ";
}
else
{
echo "error";
}
After authorize.php, the user will be in the page where he can do his job (addition, deletion....). Here how will I know that he is user x, not user y who is logged in at the sametime? Is session_start() line on every page enough?