Jump to content

[SOLVED] Cookie problem.


NArc0t1c

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/68867-solved-cookie-problem/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/68867-solved-cookie-problem/#findComment-346178
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.