Hi. I am have a members site with 2 databases. This is working perfectly in normal use, however, I am now trying to make it bullet-proof by adding a few security features (ie - if they hit F5)
I am using this to see if the person has applied :
If the user exists, they are added to members db, then deleted from the "applied" db. As I have said, this is working fine - am following the info in the database through each step. However, after the member has been deleted from this db, if they hit F5, or call the php file from the browser, $_SESSION[exists] still returns as 1.
If I put two echo statements for $_SESSION[exists] = "1"; , one at beginning and one at end, it returns 0, 1. - even though there is no member in the db anymore.
Help....lol. I have solved a lot of other issues myself, blocking pages if not authorised and the like, but this has me completely stumped.
nb - this only occurs after a successful membership app. All other times, it is working as it should. Have also checked that $_SESSION[email] is retaining correct email address.
Last edited by max2474; 05-09-2012 at 08:58 PM.
Reason: clarity
The code you're showing doesn't include everything you described in your problem. You haven't shown where you insert a member. You haven't shown where you delete a member. We can't find problems if we can't see the code.
But in the mean time, you have bigger problems. Your code is vulnerable to SQL injection. It's one of the most common security issues, but it's also one of the easiest to prevent.
The reason I have showed only this is because this is the code where the problem lies. I have a few thousand lines. I have protected against injection attacks, I was trying to find out if there are any problems with what you see.
I will post what you ask, let me just try and shrink it first.
I am starting to believe this is a "bug" of sorts... I have merged the two databases into one. I have also put all of the contents into one page (removing the need for "require") to help source the problem.
I originally ran the following script with the third line setting "exists" to 2 rather than 4. after changing it to 4 and saving, I ran the page again by hitting F5
Code:
<?php session_start(); ?>
<?php
$_SESSION[exists] = "4";
if(($_SESSION[exists] <> "1") && ($_SESSION[passes] == "0") && (!empty ($_SESSION[user])) && (!empty ($_SESSION[email])) && (!empty ($_SESSION[userpass]))
&& (!empty ($_SESSION[squestion])) && (!empty ($_SESSION[sanswer])) && (!empty ($_SESSION[terms])))
{
$_SESSION[exists] = "4";
require("pwinfo.php");
$con = mysql_connect($servername,$username,$password);
if (!$con)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db("metcoldb", $con);
$result = mysql_query("SELECT email FROM apply
WHERE email = '$_SESSION[email]' LIMIT 1");
while($row = mysql_fetch_array($result))
{
$_SESSION[exists] = "4";
}
mysql_close($con);
if($_SESSION[exists] = "2")
{
require("pwinfo.php");
$con = mysql_connect($servername,$username,$password);
if (!$con)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db("metcoldb", $con);
$sql = "INSERT INTO members (email, password, squestion, sanswer, joindate, usertitle)
VALUES
('$_SESSION[email]','$_SESSION[userpass]','$_SESSION[squestion]','$_SESSION[sanswer]','$_SESSION[date]','$_SESSION[user]')";
if (!mysql_query($sql,$con))
{ die('Error: ' . mysql_error()); }
mysql_close($con);
require("pwinfo.php");
$con = mysql_connect($servername,$username,$password);
if (!$con)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db("metcoldb", $con);
mysql_query("DELETE FROM apply WHERE email = '$_SESSION[email]' LIMIT 1");
mysql_close($con);
/* $_SESSION[exists] = "3"; */
echo "added";
}
}
else
{
echo"not added";
}
?>
<p>currently registered info is as follows:</p>
<?php echo "registered email is ".$_SESSION[email];?><br/>
<?php echo "registered exists is ".$_SESSION[exists]; ?><br/>
output is
added
currently registered info is as follows:
registered email is fgfg@sdds
registered exists is 2
if the
Code:
/* $_SESSION[exists] = "3"; */
at the bottom runs, output is three. stop it, and back to 2.
Bookmarks