D
D
Dmitry Filippov2017-08-23 14:25:13
PHP
Dmitry Filippov, 2017-08-23 14:25:13

Why are cookies not working in php?

Hello. I have a very strange problem.
I set cookies in php, after which I redirect to the private part of the site. But for some reason, cookies are simply not set and I am thrown back to the main page (due to a script that checks authorization). But after that, if I log in, these cookies appear from somewhere. In what there can be a trabl?
Authorization code:

$time = time()+60*60*24*30;
                
$id = $result->ResponseObject->ID;
                
setcookie("id", $id, $time);
setcookie("hash", Users::StringEncode($id), $time);
                
header("Location: /home");

Authorization check code:
public static function CheckAuth(){
      
      if(isset($_COOKIE['id']) && isset($_COOKIE['hash'])){
        
        $id = $_COOKIE['id'];
        $hash = $_COOKIE['hash'];
        
        if(self::StringEncode($id) == $hash) return true;
        else return false;
      
      }else{
        return false;
      }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pushkarev, 2017-08-23
@HorrorInferno

Like this:

setcookie("hash", Users::StringEncode($id), $time, '/');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question