Hi,
I'm in a big mess. We have a lan at work and internet access is shared using winproxy.
I just discovered that if a person has logged in , another person who opens up index.php gets to view the first persons page !
I dont know if this is because of the shared net connection or whether its a flaw in the script.
Also, if one person has logged in, another person having access to the u/n and p/w can log in to the account at the same time. Clearly, my login.php and index.php are flawed and I would appreciate if someone can help guide me on how I should change it.
Thanks.Swati
Login.php
<H3><p><p align="center">Login to access your webpage:<P>
<FORM METHOD=post ACTION="<? echo $PHP_SELF ?>?action=login">
<p><p><p>
<B><table cellspacing="5" BORDERCOLORLIGHT = "#FFFF00" BORDERCOLORDARK = "#FFFF00" bgcolor="#003498" align="center" border="8" >
<tr align="left"><td><font color="yellow" size="3" face="Tahoma"> User Name:</td><td>
<INPUT TYPE=text SIZE=30 NAME=loginname></td>
<td><font color="yellow" size="3" face="Tahoma"> Password:</td><td>
<INPUT TYPE=password SIZE=30 NAME=password></td></tr></table>
</center> <br>
<p align="center"><INPUT TYPE=submit VALUE="Sign In"> </p>
</FORM>
</tr>
</table>
Index.php
<?include("protect.php") ; ?>
<?php
mysql_connect("localhost", $dbname, $dbpasswd )
or die ("Unable to connect to server.");
mysql_select_db($database)
or die ("Unable to select database.");
$sql = "SELECT *
FROM users
WHERE (username='$logincookie[user]' or username='$loginname') and (md5(password)='$logincookie[pwd]' or password='$password')";
$result = mysql_query($sql)
or die ("Unable to get results.");
printf("<font face=\"Verdana\" size=\"4\"><font color=\"blue\">Welcome <b>%s %s</b>", mysql_result($result,0,"firstname"), mysql_result($result,0,"lastname") );
if (mysql_result($result,0,"type") == 'Sales')
{
$uid=mysql_result($result,0,"uid");
printf("<p><a href=sales.php?uid=$uid>Click here to proceed to your options</a>");
}
if (mysql_result($result,0,"type") == 'Finance')
{
$uid=mysql_result($result,0,"uid");
printf("<p><a href=finance.php?uid=$uid>Click here to proceed to your options</a>");
}
<p><p><br>
<font face="Verdana" size="2">Make sure you sign out once you have completed your visit to the site.<br><b>
<A HREF="<? echo $PHP_SELF ?>?action=logout">Sign Out</A></b><br><br>
</td>
</tr>
</table>
Protect.php
<?
// This is the page to show when the user has been logged out
$logout_page = "logout.php";
$dbname = "x";
$dbpasswd = "y";
$database = "z";
// Page with login form
$login_page = "login.php";
// Page to show if the user enters an invalid login name or password
$invalidlogin_page = "invalidlogin.php";
if ($action == "logout")
{
Setcookie("logincookie[pwd]","",time() - 3600);
Setcookie("logincookie[user]","",time() - 3600);
include($logout_page);
exit;
}
else if ($action == "login")
{
if (($loginname == "") || ($password == ""))
{
include($invalidlogin_page);
exit;
}
mysql_connect("localhost", $dbname, $dbpasswd )
or die ("Unable to connect to server.");
mysql_select_db($database)
or die ("Unable to select database.");
$sql = "SELECT * FROM users WHERE username='$loginname' ";
$result = mysql_query($sql)
or die ("Unable to get results.");
$myrow = mysql_fetch_array($result);
if (strcmp($myrow["password"],$password) == 0)
{
Setcookie("logincookie[pwd]",md5($password),time() + 3600);
Setcookie("logincookie[user]",$loginname,time() + 3600);
}
else
{
include($invalidlogin_page);
exit;
}
}
else
{
if (($logincookie[pwd] == "") || ($logincookie[user] == ""))
{
include($login_page);
exit;
}
mysql_connect("localhost",$dbname, $dbpasswd )
or die ("Unable to connect to server.");
mysql_select_db($database)
or die ("Unable to select database.");
$sql = "SELECT * FROM users WHERE username='$logincookie[user]' ";
$result = mysql_query($sql)
or die ("Unable to get results.");
$myrow = mysql_fetch_array($result);
if (strcmp(md5($myrow["password"]),$logincookie[pwd]) == 0)
{
Setcookie("logincookie[pwd]",$logincookie[pwd],time() + 3600);
Setcookie("logincookie[user]",$logincookie[user],time() + 3600);
}
else
{
include($invalidlogin_page);
exit;
}
}
?>
<?php
function calculatedate($inputdate)
{
$inputdate_parts = explode('-', $inputdate);
if ($inputdate_parts[1]==00 && $inputdate_parts[2]==00 && $inputdate_parts[0]==0000)
return ' ';
// Calculating the UNIX Timestamp for both dates
$x = mktime(0, 0, 0, $inputdate_parts[1], $inputdate_parts[2], $inputdate_parts[0]);
$outputdate = date('d.m.y', $x);
return $outputdate;
}
?>