In order to prevent CSRF attacks, I want to understand one thing. In my website I created $_SESSION['logged'] for a user, only when he login. When the user use my website, the $_SESSION['logged'] is exists, of course. I will explain what I want with some code.
This is the checkLogin.php, that checks if $_SESSION['logged'] is exists:
<?php
//checkLogin.php
session_start();
session_regenerate_id();
if( !isset($_SESSION['logged']) )
{
die('You are not logged.');
}
else
{
// do something like mysqli query...
die('You are logged.');
}
?>
My question: If a logged user send a request to checkLogin.php not from my domain, the $_SESSION['logged'] will be setted or not? What the response will be:
die('You are not logged.');
or
die('You are logged.');
?
I checked that with cURL and the response is always: die('You are not logged.');
<?php
//test.php
session_start();
session_regenerate_id();
$url = "http://localhost/form.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_exec($ch);
?>
Despite that test, I want to be sure if any request to checkLogin.php not from my domain can somehow print die('You are logged.');
Thanks.