NArc0t1c Posted September 11, 2007 Share Posted September 11, 2007 Hello. I have a login page, actually it is a page that calls the login page trough ajax. I am having a problem, the login cookie is not being created by the php script. I do the validation with php and javascript, here is a example of how data gets sent. [pre] Javascript <- Ajax Receives <- PHP Script < ( ) > HTML -> Javascript Validation -> Ajax Sends [/pre] Well, In theory it should work, but I can't find any reason why the cookie is not being created. Here is my script, sovar; <?php define("MYSQL", "TRUE"); require("mysql_db.php"); if (isset($_POST)) { $email = htmlspecialchars(strip_tags($_POST['email'])); $passwd = htmlspecialchars(strip_tags($_POST['password'])); $passwd = md5($passwd); $query = mysql_query("SELECT mid,m_email,m_password FROM members WHERE m_email='$email' AND m_password='$passwd'", $connect); if (mysql_num_rows($query) != 1) echo 'Invalid Username/Password.'; else { $data = mysql_fetch_array($query); $cookie = setcookie("GA_login", $data['mid'] . ":" . $data['m_email'] . ":" . $data['m_password'], time() + 3155760000,"/",$_SERVER['HTTP_HOST']); if (!$cookie) echo 'Please enable cookies.'; else echo $_COOKIE['GA_login'] . 'Login Done.'; } } mysql_close($connect); ?> Any help on this? Ferdi Quote Link to comment https://forums.phpfreaks.com/topic/68867-solved-cookie-problem/ Share on other sites More sharing options...
gerkintrigg Posted September 11, 2007 Share Posted September 11, 2007 replace the !=1 with <1 perhaps there are duplicate entries for this user..? I presume that you're using the correct parsing method to this script... ie. the variables ARE being posted? Quote Link to comment https://forums.phpfreaks.com/topic/68867-solved-cookie-problem/#findComment-346142 Share on other sites More sharing options...
NArc0t1c Posted September 11, 2007 Author Share Posted September 11, 2007 I changed my script; <?php define("MYSQL", "TRUE"); require("mysql_db.php"); if (isset($_POST['email']) && isset($_POST['password'])) { $email = htmlspecialchars(strip_tags($_POST['email'])); $passwd = htmlspecialchars(strip_tags($_POST['password'])); $passwd = md5($passwd); $query = mysql_query("SELECT mid,m_email,m_password FROM members WHERE m_email='$email' AND m_password='$passwd'", $connect); if (mysql_num_rows($query) < 1) echo 'Invalid Username/Password.'; else { $data = mysql_fetch_array($query); $cookie = setcookie("GA_login", $data['mid'] . ":" . $data['m_email'] . ":" . $data['m_password'], time()+43200000); if (!$cookie) echo 'Please enable cookies.'; else echo $_COOKIE['GA_login'] . 'Login Done.'; } } else echo 'Yes..\?'; mysql_close($connect); ?> Seems to be working now, I think it was my path/host. Thanks Ferdi Quote Link to comment https://forums.phpfreaks.com/topic/68867-solved-cookie-problem/#findComment-346178 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.