M
M
Maxim Kalinin2020-04-28 09:06:11
PHP
Maxim Kalinin, 2020-04-28 09:06:11

Using functions from one php file in another?

I include the core.php file in the core.api.php file to use the functions contained in it.

define(ROOT, $_SERVER['DOCUMENT_ROOT']);
require(ROOT.'/sys/core.php');


From the core.php file, you need to use a function with the following parameters:
function check($pdo, $cookie_id, $cookie_hash){
        
        if(empty($cookie_id) || empty($cookie_hash)){
            return 0;
        } else {
            $sql = "SELECT hash FROM nv_users WHERE id='$cookie_id'";
            if(!$stmt = $pdo->query($sql)){
                return 0;
            } else {
                $row = $stmt->fetch(PDO::FETCH_ASSOC);
                if(!$row){
                    return 0;
                } else {
                    $db_hash = $row['hash'];
                    if($cookie_hash == $db_hash){
                        return $cookie_id;
                    }
                    return 0;
                }
            }
        }
    }


But everything that is returned to the core.api.php file == 0;
Because of this, it is not possible to correctly verify the information.
BUT I connect the same core.php file to index.php and everything works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2020-04-28
@MaximAr1es

As always, the cockroach has ears in its legs.
If a function doesn't work, it's because it's being called from another file. Of course, how else?
If a function does not return what is expected, it means that incorrect data was passed to it.
Here is the data that you transmit, and you need to look.
Instead of on a file in which function lies.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question