zimmo Posted May 13, 2010 Share Posted May 13, 2010 Safari browser will not accept my cookie it is ignoring it? have I done something wrong with how the cookie is presented for safari??? The cookie I try to set: setcookie('peg', 'YES', 'time()+190', '', 0); Also all browsers are starting my phpsession off when its not even declared until after the post request? Can someone please help and tell me why my session is getting set, as when I go to the page I can see that the php session is being set as I check the cookies it has the phpsession there? Totally puzzled? Here is my code again. <?php // Include the connections script to make a database connection. include("inc/connect.php"); $username = ""; $password = ""; $errorMessage = ""; function quote_smart($value, $handle) { if (get_magic_quotes_gpc()) { $value = stripslashes($value); } if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value, $handle) . "'"; } return $value; } if ($_SERVER['REQUEST_METHOD'] == 'POST'){ $username = $_POST['username']; $password = $_POST['password']; $username = htmlspecialchars($username); $password = htmlspecialchars($password); $db_found = mysql_select_db($db, $connection); if ($db_found) { $username = quote_smart($username, $connection); $password = quote_smart($password, $connection); $SQL = "SELECT * FROM tablea WHERE username = $username AND password = '".md5($_POST['password'])."'"; $result = mysql_query($SQL); $num_rows = mysql_num_rows($result); if ($result) { if ($num_rows > 0) { session_start(); $_SESSION['username'] = "$_POST[username]"; header ("Location: index.html"); } /* New Block Log in attempts*/ else { session_start(); $_SESSION['attempts'] = "+1"; # setup SQL statement $SQL = " INSERT INTO tableb "; $SQL = $SQL . " (sid, username, password, attempts, ipaddress) VALUES "; $SQL = $SQL . " ('$_COOKIE[phpSESSID]', '$_POST[username]', '$_POST[password]', '$_SESSION[attempts]', '$_SERVER[REMOTE_ADDR]') "; #execute SQL statement $result = mysql_db_query( *****,"$SQL",$connection ); # check for error if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } else { # setup SQL statement 2 $SQL = "SELECT * FROM tableb WHERE sid = '$_COOKIE[phpSESSID]' "; $result = mysql_query($SQL); if (mysql_num_rows($result) ==0) { $errorMessage = "Please check your username and/or password is correct"; } elseif (mysql_num_rows($result) >=3) { header ("Location: index2.html"); } else { $errorMessage = "Please check your username and/or password is correct"; } } } /* END */ } else { $errorMessage = "Please check your username and/or password is correct"; } mysql_close($connection); } else { $errorMessage = "Please check your username and/or password is correct"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/201602-how-is-the-session-getting-set-and-safari-not-accepting-the-cookie/ Share on other sites More sharing options...
Muddy_Funster Posted May 13, 2010 Share Posted May 13, 2010 Are you calling the session_start in connect.php as well by chance? Quote Link to comment https://forums.phpfreaks.com/topic/201602-how-is-the-session-getting-set-and-safari-not-accepting-the-cookie/#findComment-1057636 Share on other sites More sharing options...
zimmo Posted May 13, 2010 Author Share Posted May 13, 2010 Hi again muddy. No, thats the thing the connection is standard, not session there. Its totally puzzling me as to how that is getting set, and its annoying me that I cannot find anything on google about the safari browser and cookies and the correct php way to write them for that browser. You can see in my code that the session is not declared until after the post. Quote Link to comment https://forums.phpfreaks.com/topic/201602-how-is-the-session-getting-set-and-safari-not-accepting-the-cookie/#findComment-1057637 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.