I want know if it's possible to keep PHP sessions alive between two requests...
I do the requests using Flurl plugin:
public const string ApiUrl = "http://localhost/z/api.php";
public static string MethodName()
{
using (FlurlClient client = new FlurlClient())
{
string res = client.HttpGet(string.Format("{0}?action={1}", ApiUrl, "captcha"), true);
//Some actions...
return client.HttpPost(ApiUrl, new { action = "resolve-captcha", input = r }, false);
}
}
public static string HttpPost(this FlurlClient client, string url, object data, bool keepalive = false)
{
return client.Request(url).PostUrlEncodedAsync(data).ReceiveString().GetAwaiter().GetResult();
}
public static string HttpGet(this FlurlClient client, string url, bool keepalive = false)
{
return client.Request(url).GetStringAsync().GetAwaiter().GetResult();
}
And in the PHP part (API):
//if isset $_GET then switch action key...
case "captcha":
if (session_status() == PHP_SESSION_NONE)
session_start();
$_SESSION['phrase'] = "hello";
break;
//if isset $_POST then switch action key...
case "resolve-captcha":
$secret = @$_SESSION["phrase"];
if(session_status() == PHP_SESSION_NONE)
die("No session!");
else
$coreData["secret"] = $secret;
$input = @$_POST["input"];
$coreData["valid"] = $input === $secret;
break;
But for some reason, every time I do the next step (Post) the api returns that there isn't any session running.
As you can see here:
I have been reading and all the answers says the same, that I have to use cookies, cookies for what? To store the secret that the server should keep? I need to know how can I do two requests with the same session or at least if this is possible, because I don't want to use MySQL (with an ID system, ie), I prefer to keep it easy.