session save path permission issues

by deva 2007-08-23 16:23:08

Hi try the below php code to set session variables;

<?php
session_start();
if (!isset($_SESSION["count"]))
$_SESSION["count"] = 1;
else
$_SESSION["count"]++;
?>
<p>
Hello visitor, you have seen this page <?php echo $_SESSION["count"]; ?> times.
</p>


If the above code does not work, problem might be in permissions of the folder in which the sessions are being saved. Test below function to know where your sessions are currently being saved:

echo session_save_path();

After knowing the folder where your sessions are saved, check out the file permissions for that folder. If that folder does not have enough permissions, set permissions atleast 555 for that folder. Also check out the httpd_sys_content_t permission for that folder. To set this permission, use:

chcon -R -h -t httpd_sys_content_t foldername/ [note: this command in linux]

You can also set your own session_save_path by using below function: Note that setting the session_save_path should be done before session_start(). And also make sure the folder given in the session_save_path exists.

echo session_save_path("/home/dvvel/session");

Tagged in:

2468
like
0
dislike
0
mail
flag

You must LOGIN to add comments