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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.