I'm attempting to implement basic session handling as follows:
PHP File 1 - login after various checks for the user and password etc in database I would like to give this user a session
<?php
...
session_start();
PHP File 2 - before executing any logic in file 2 I would like to see if a valid session exists for the session that I believe would exist in the request PHPSESSID header?
<?php
$sessionID = session_id();
if ($sessionID === '') {
echo 'no session found';
} else {
echo 'session found.';
}
I have attempted to start a new session in PHP file 2 which will return a value but the problem I have then is that if someone remotely attempts to execute a php file on my server, example https://example.com/folder1/php/loaddata.php they will simply be given a new session I and be allowed to execute the file.