简体   繁体   English

PHP的:session_start()

[英]PHP : session_start()

Whenever I try to use session_start() [ at the very top of my file as it should be ] it gives me the following: This webpage is not available, which otherwise is not displayed when I do not use sessions. 每当我尝试使用session_start() [应该在文件的最顶部]时 ,都会为我提供以下内容:该网页不可用,否则当我不使用会话时不会显示该网页。 I would really appreciate any help. 我真的很感谢您的帮助。

Here is only a simple code for demonstration: 这只是一个简单的演示代码:

<?php
// Start the session
session_start();

?>
<!DOCTYPE html>
<html>
<body>

<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>

</body>
</html>  

i think It's the permission issue on the session folder. 我认为这是会话文件夹上的权限问题。 The start_session() failed to create session. start_session()无法创建会话。 to get the location of the sessions folder use the function sys_get_temp_dir(): 要获取会话文件夹的位置,请使用sys_get_temp_dir()函数:

<?php

  echo sys_get_temp_dir();

after you found the location, if you are using Linux and Apache, you should change the group of the folder that you have founded 找到位置后,如果您使用的是Linux和Apache,则应更改已创建文件夹的组

sudo chgrp www-data /the folder that you got from sys_get_temp_dir()/ sudo chgrp www-data /从sys_get_temp_dir()/获得的文件夹

Get or set your session path session_save_path() 获取或设置您的会话路径session_save_path()


  session_save_path();

Maybe session is required permissions 会话可能是必需的权限

Try it for permission 尝试获得许可



sudo chmod -R 775 /yoursessionpath

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM