PHP设置cookie未设置

时间:2015-07-16 09:22:07

标签: php mysql wordpress cookies

这是我的代码,我知道SQL正在返回结果,因为我已经检查过了。但是,设置cookie似乎不起作用。

 public function login($username, $password){


    $username = $_POST['username'];
    $password = md5($_POST['password'].THEME_SALT);

    global $wpdb; 
    $result = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}users WHERE username ='".$username."' AND password ='" .$password."' LIMIT 1");

    if (!empty($result)){

        setcookie("user", $username, time() + 3600);
    }
        return false;
}

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

尝试使用:

public function login($username, $password){

      $username = $_POST['username'];

       if ( username_exists( $username ) ){
           echo "Username In Use!";
            setcookie("user", $username, time() + 3600);
      } else{
               echo "Username Not In Use!";
      }
}

答案 1 :(得分:0)

尝试添加路径

DateTime.AddHours(1)