douwenan9849 2015-12-01 17:03
浏览 184
已采纳

PHP session_start错误(没有找到这样的文件或目录)

I am fairly new to PHP and I am trying to create a login system where the the username is stored in PHP cookie through session. So through a video tutorial I learnt that I use session_start(); to start the the cookie session then set the variable if the condition is met. I am using XAMPP to test my PHP, so when I load the page, I get this error:

Warning: session_start() [function.session-start]: open(Desktop\xampp\tmp\sess_5bre7v153kb1hoftovugl77o52, O_RDWR) failed: No such file or directory (2) in C:\Users------\Desktop\xampp\htdocs[folder]\checkLogin.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Users----\Desktop\xampp\htdocs[folder]\checkLogin.php:2) in C:\Users----\Desktop\xampp\htdocs[folder]\checkLogin.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php:2) in C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php:2) in C:\Users----\Desktop\xampp\htdocs[Folder]\checkLogin.php on line 19

Warning: Unknown: open(----\Desktop\xampp\tmp\sess_5bre7v153kb1hoftovugl77o52, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (----\Desktop\xampp\tmp) in Unknown on line 0**

I do have a temp folder in my XAMPP files, where it specifies that do not delete this folder as it has to be there for PHP to create sessions. Here is my PHP code:

    <?php
session_start ();
if (isset($_POST["submit"])) {
  $username = $_POST["username"];
  $password = $_POST["password"];
  $check = false;
  $information = fopen("user_information.txt", "r");
  while (!feof($information)) {
    $content = explode(":", rtrim(fgets($information, 1024)));
    if ($username == $content[0] && ($password) == $content[1]) {
         $check = true;
         break;
    }
  }
  fclose($information);

  if ($check) {
     define('BASE_URL', 'index.php');
     header('Location: ' . BASE_URL);
     $SESSION["username"] = $username;
    }
  else {
     define('BASE_URL', 'login.php');
     header('Location: ' . BASE_URL);
  }
    }
?>

Thank you

  • 写回答

1条回答 默认 最新

  • dtx9931 2015-12-01 18:07
    关注

    It's a configuration error.

    Check the line below on your php.ini file:

    session.save_path = "/tmp"
    

    Or in your PHP script:

    session_save_path('/home/example.com/sessions');
    

    That line tells to PHP where session files will be saved.

    The system user that are running the server need to have write privileges on this folder.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?