Magic_quotes_gpc is active on my server, and I do not apply any addslashes or stripslashes functions to my gpc data.
When a user submits my login form, the following is run:
$sessionHash = session_id();
$username = $_POST['username'];
$password = $_POST['password'];
$s_credentials = "SELECT userID FROM user WHERE username=' ".$username." ' AND password=' ".$password." ' ";
$q_credentials = @mysql_query($s_credentials);
$r_credentials = @mysql_fetch_array($q_credentials);
if (mysql_num_rows($q_credentials)=="1")
{
// Use the user's ID# to get info for the session
$s_getuserinfo = "SELECT username FROM user WHERE u.userID=' ".$r_credentials['userID']." ' ";
$q_getuserinfo = @mysql_query($s_getuserinfo);
$r_getuserinfo = @mysql_fetch_array($q_getuserinfo);
// Update the current session
$s_updatesession = "UPDATE session SET userID=' ".$r_credentials['userID']." ', username=' ".$r_getuserinfo['username']." ' WHERE sessionHash=' ".$sessionHash." ' ";
$q_updatesession = @mysql_query($s_updatesession);
echo "You are now logged in, $username.";
}
else
{
echo "You have entered an invalid login.";
}
Under normal circumstances, this works fine, and the user's session record is updated appropriately in the DB.
This doesn't work out so well when the user has an apostrophe in their username. When this is the case, the "You are logged in" message will display, and a slash is inserted before each apostrophe of their name.
For example, the username is World's Greatest O'Reilly. Here is the output:
You are now logged in, World\\'s Greatest O\\'Reilly.
Along with this oddity, the user's session table in the DB goes untouched. Does this sound like an issue with magic_quotes being turned on, or could something else be the problem?