javascript - authenticate via .htaccess on custom login
So my problem is this - i have custom authenticate code that writes in db `online` table ip, session id and user id(if login and password match) based on registered user data.
Soo i have some js scripts that are only needed when you are authenticated and i dont want them to be accessible if you are not logged in(its not unsecured but why to give playground), and i want all the script to be in one .js file.
Soo i thoght maybe i can make that folder with .htacces password protection and when i log into admin panel some php code make me also logged in in that appache system - is this possible? or i need to make js file php and then include it or something else? im baffled.
Answer
Solution:
Sure you can do that! But there is a much simpler way. Just use a php file as your script tag's
src
attribute, and setup that file to handle the request:The PHP file controls which Javascript is sent to the client. This is because PHP script can tell whether the user is logged in by looking at
$_SESSION
variables:js_handler.php