Hey,
I'm currently working on something at the moment that requires sessions, and to be honest before about two weeks ago, I've never used them.
The following is what I came up with to check if sessions are set and / or valid, but before I go ahead and use this at the top of a ton of pages I though I'd check if much better people than me think its sufficient.
Are there any gaping secutiry holes? Have I missed anything obvious that you think I should be checking? Is this compleatly wrong? 😃 And, of course, if anyone can suggest ways this can be done better (if needed), i'd apreciate any thoughs you have.
Many thanks.
session_start();
include('/home/userName/configure/smallConfigure.php');
if( (!isset($_SESSION['sesUSER'])) or (!isset($_SESSION['sesPW'])) or (!isset($_SESSION['sesSellerID'])) )
{
header("Location: " . $thisSiteToRoot . "guest/logIn/");
exit();
}
include('/home/' . $adminUserName . '/configure/configure.php');
@ $con = mysql_connect($masterHost,$masterUN,$masterPW);
if(!$con)
{
header("Location: " . $thisSiteToRoot . "error/service/");
exit();
}
@ $selectDB = mysql_select_db( $sellerDB, $con );
if(!$selectDB)
{
mysql_close( $con );
header("Location: " . $thisSiteToRoot . "error/service/");
exit();
}
$user = mysql_real_escape_string($_SESSION['sesUSER']);
$password = mysql_real_escape_string($_SESSION['sesPW']);
$sellerID = mysql_real_escape_string($_SESSION['sesSellerID']);
$sql ="SELECT sellerID FROM seller WHERE sEmail='$user' and password='$password'";
@ $rs = mysql_query( $sql, $con );
if(!$rs)
{
mysql_close( $con );
header("Location: " . $thisSiteToRoot . "error/service/");
exit();
}
$num = mysql_num_rows( $rs );
if( ($num == 0) or ($num > 1) )
{
mysql_close( $con );
header("Location: " . $thisSiteToRoot . "guest/logIn/");
exit();
}
@ $row = mysql_fetch_assoc( $rs );
if(!$row)
{
mysql_close( $con );
header("Location: " . $thisSiteToRoot . "error/service/");
exit();
}
$sellerIDCalled = $row['sellerID'];
$indexCalled = $row['index'];
mysql_close($con);
if( $sellerIDCalled != $_SESSION['sesSellerID'] )
{
header("Location: " . $thisSiteToRoot . "guest/logIn/");
exit();
}