Suppose your home machine does not have:
session.autostart = On
in php.ini , while your other machine is explicitly.
Make sure you install in your PHP code:
session_start();
PHP: session_start - manual
If you do not, your session will not start if my first hypothesis is not true.
In addition, you should check the PHP version on your local host and settings in php.ini. Verify that the directory where the session files are stored can be written, and that the session files do exist.
EDIT 1:
Better use a PHP redirect solution:
header("Location: /"); exit();
EDIT 2:
PHP has functions that change HTTP headers. Some of them:
EDIT 3:
Line breaks and spaces can be a problem, but there are also invisible character sequences that can trigger Warning: Cannot modify header information , like the UTF-8 Specification (Byte-Order-Mark) . Try saving the file again, making sure it is saved as UTF-8 (no BOM) .
EDIT 4:
To properly debug your code, make sure that PHP displays all warnings and notifications. Run it before the session starts:
ini_set('display_errors', -1);
EDIT 5:
You should also check the session.gc_maxlifetime setting:
session.gc_maxlifetime
session.gc_maxlifetime indicates the number of seconds after which data will be considered garbage and cleared. Garbage collection occurs during the start of the session.
EDIT 6:
To view spaces in Sublime Text, edit the settings:
// Set to "none" to turn off drawing white space, "selection" to draw only the // white space within the selection, and "all" to draw all white space "draw_white_space": "selection",
You can set it in Settings-> Default Settings. If you change your user settings "Settings" → "Settings" - "User" and add the line as shown below:
{ "font_size": 10, "draw_white_space": "all" }
Also make sure that it displays all other special characters to properly debug your code!
EDIT 7:
Finally, try adding session_write_close(); right before the redirect.
EDIT 8:
Install PHP into your file, before the session_start(); directive session_start(); , session.save_path = "/home/username/tmp"; . Create tmp dir outside of public_html. Make sure tmp dir has chmod 770 and is created with the same user / group privileges. Run ls -lsa in your home directory to check if the new directory has the same user / group as other directories, for example public_html. If not, make sure you change the administrative permissions to tmp by running chown username:groupname /home/username/tmp .