4

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

3
  • 1
    If you run Apache as a service it's very unlikely that it has permission to write into your desktop. You should move Xampp elsewhere. Commented Dec 1, 2015 at 17:06
  • Have you checked Apache has write permissions to the directory?
    – SteJ
    Commented Dec 1, 2015 at 17:08
  • Is there a way I can do that? Thanks! On a side note, I cannot access anything that requires admin rights...
    – arthrax
    Commented Dec 1, 2015 at 17:43

1 Answer 1

6

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.

1
  • session.save_path = "/tmp/"
    – Exp3rt
    Commented Jun 2, 2018 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.