I'd like to store the session when I redirect to another PHP file using javascript's window.location. But somehow, the session is always missing on the server while it's fine on my localhost. The server is still using an IP Address like this: http://1.1.1.1/app/check_session.php. The server is using CentOS. What I used here as the root path is the /app, is it cause the problem?
UPDATE:
session_id()changed after redirect tocheck_session_submit.phpbefore > after, even refresh thecheck_session.phpit keeps changing
Here's my code:
check_session.php
<?php
session_start();
echo "Session Path: ".session_save_path()."<br>";
echo "Session ID: ".session_id()."<br>";
$_SESSION["test"] = "test";
?>
<html>
<head>
<script>
function delayer(){
window.location = "check_session_submit.php";
exit();
}
</script>
</head>
<?php
if(isset($_POST["field_1"])){
$_SESSION["field_1"] = $_POST["field_1"];
?>
<body onLoad="setTimeout('delayer()', 1)">
<?php
}
?>
<form method="POST">
<input type="text" name="field_1">
<input type="submit">
</form>
</body>
</html>
check_session_submit.php
<?php
session_start();
echo "Session Path: ".session_save_path()."<br>";
echo "Session ID: ".session_id()."<br>";
echo "Session Data: ".json_encode($_SESSION);
?>
I have followed the instructions given here: https://stackoverflow.com/a/17242347/9858781 but still no luck. Tried to save the session into the specified path as mentioned in that comment .../app/cgi-bin/tmp and add the permission to directories by using chmod 777, but still, the session is not saved. I tried to check the Apache error log from /var/log/httpd/error_log and there's no error reported. Is there anything else that I can look into?
Here's my server session configuration:
session.save_path = "/tmp"
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.serialize_handler = PHP
session.gc_maxlifetime = 1440
session.gc_divisor = 1000
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
These are the HTTP headers from the server response: server response HTTP header