I've been learning PHP for a couple of days now and I came across a strange issue for me. I have two files :
login.php
that stores database access data (user, pw, host, db)
security.php
that have functions that manipulate strings/queries to prevent sql/xss injections and also stores salt prefix and suffix for password hashing.
Then I have my index.php
, register.php
and signin.php
. My problem is : when I put require_once '../login.php';
in register.php
I can normally call a variable or function like $var. On the other hand, exactly the same pattern in signin.php
is not working, PHP tells that that variables are not declared. I tried to do : global $var
, and it was working but I have feeling that it's completely insecure.
1) What is the proper way to solve this problem?
2) Is it connected with app architecture?
3) Should all functions (and etc.) that use db connection be written in a single file?