PHP session warning in Windows IIS - php

Error during session start; please check your PHP and/or webserver log file and configure your PHP installation properly. Also ensure that cookies are enabled in your browser.
session_start(): open(C:\Windows\TEMP\sess_3ls3qdk77m9mhsf5tm1cdhrm05bi5kb1, O_RDWR) failed: Invalid argument (22)
in my php.ini file: session.save_path = "C:\temp\phpsessions"
Before it was working fine. So sudden it is showing an error.
anyone can assist with this please.

As already stated by other, there is a chance that
Either the C:\temp\phpsessions directory doesn't exist,Or
Else IIS_IUSRS Read/Write Permission is missing in C:\Windows\Temp
there is no problem with your browser.

Double check the permissions on C:\Windows\Temp\ folder. I think IIS_IUSRS needs to have write access in order for files to be saved.
Consider moving the session folder out of C:\Windows\
Where ever you put the sessions, iis will need permissions to edit it.

PHP will not create this directory structure automatically. So make sure this C:\temp\phpsessions directory exist. If not, then you can use the script in the ext/session dir for that purpose or create that directory structure manually.
and then
You can change session save path by writing this line for created directory before session start also note here extra '\' because of escape character.
session_save_path("C:\\temp\\phpsessions");

Most probably it is browser problem. Some mistmatch between browser and session data.
Just in case please do the following:
1. Clear the cache, cookies and temp data of your browser (or use another browser for experimental purposes).
2. Clear the directory where session files are stored on serverside (in your case it seems it is C:\Windows\TEMP or C:\temp\phpsessions. Better clean both of them).
If it does not work please share your php.ini file.

Related

Sessions storage php/nginx

I'm having trouble with session variable in my setup. I'm storing some data in SESSION variables, but it seems like they're not stored properly, or at least I can't access them. On my local computr running MAMP it works ifne but in prod with php5/nginx, my session variables aren't stored. (I get an undefined index error).
I've read it can be related to the session.save_path and access rights, but I'm still confused. Where is this path defined? In my php.ini file there is this
;session.save_path = "/var/lib/php5"
But it starts with a ';' so I'm guessing it's ignored?
Also, what access should I give to the folder (once I've found it)? How can I know which user php is, and which group it belongs to? Seems like really basic stuff but I'm struggling to grasp it u__u
EDIT:
Apparently it's not a problem of permissions, since there are a lot of session folders in the directory, all created by php... So I really can't figure out why my session variables aren't accessible! :-(
It says undefined index...
Thanks in advance!
Aurélie
It is indeed ignored if it starts with ;. The default value is the temp directory, i.e. /tmp, but just to be sure, I suggest that you look in your phpinfo() and check it there because the file you checked might not be the only configuration your PHP uses.
The sessions path needs to be writable by PHP and it also has to be permitted by the open_basedir directive (if you use open_basedir which is highly recommended).
You use nginx so I'll assume you're using PHP-FPM. To find the PHP-FPM's user, you need to either find the user = ... directive in your php-fpm.conf (usually somewhere under /etc), or you can just find the running process using a tool like ps, htop, etc.

How can I fix the Permission error when I call session_start()?

when I uploaded the script to the server I got this error
Warning: Unknown: open(/tmp/sess_58f54ee6a828f04116c2ed97664497b2, O_RDWR) failed: Permission denied (13) 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 (/tmp) in Unknown on line 0
The error appeared when I call session_start(), although I set the permission of /tmp folder to 777.
Change session path where you can write data or contact server administrator about /tmp problem
http://php.net/manual/en/function.session-save-path.php
you will need to change your session.save_path php.ini directive
You can do that using session_save_path
If you have SSH access, here is how to correct the permission and ownership
sudo chown -R NAME_OF_USER /tmp
Replace NAME_OF_USER by the user under which runs php. You can find it by simply putting these lines in a php file:
$processUser = posix_getpwuid(posix_geteuid());
print $processUser['name'];
exit;
Check that you're not running into diskspace issues. If all the permissions are correct (and 777 ought to do it for you), then you might still get this error (for some versions of PHP and Apache) if there isn't enough space to write to the disk.
I had this problem in the following situation:
I filled some session vars with PHP
While the session was still active, I changed from PHP 5.4 to 5.3 on my host.
Reloading the page gave the error, described above.
Reset the PHP version to 5.4 again.
Used session_unset(); and session_destroy(); to clean the current session.
Changed the PHP version back to 5.3.
Now it works again.
Conclusion: For an irrelevant reason I had to change my PHP version, and while switching with sessions alive, the sessions get corrupted.
I realize that this is an old post, however I just ran into this problem, and found an easy solution.
For me, the issue was happening with one of my websites deployed locally. I hadn't tried accessing the websites using other browsers, but it was happening every time I tried to access this site via Chrome. I decided to go into the Chrome developer tools, under the application tab -- and clicking "Clear Storage". Voila -- everything is working like magic again.
Hope this helps someone else!
Additionally, you may want to use ini_set('session.save_path', '/dir/here'); assuming you have access to this function. The other ways suggested are valid.
I've just had exactly the same problem with one of my PHP scripts and I was like what did I break 'cos it worked perfectly the day before and I'm running it from my own local Puppy Linux machine so it's not even a host or anything.
The only thing I'd been doing before that was trying to get Java to work in the web browser, so some how I'd managed to get Java to work but broke PHP - oops!
Anyway I did remember that whilst trying to get Java to work I had deleted the contents of the /tmp folder to wipe anything out that may be causing a problem (it actually turned out with Java I was using the old plugin oij with the new Firefox)
To solve this problem I opened up Rox File Manager, went to the / folder and right clicked on the tmp folder -> Mount Point 'tmp' and clicked properties.
I noticed the permissions were set as Owner - Read, Write, Exec, but Group and World were only set at Read and Exec and not Write. I put a tick in Write for both Group and World and now PHP works fine again.
I don't know at what point the permissions for tmp must have changed but for PHP to use them it must be set to have Write permissions.
Add following line
ini_set('session.save_path', getcwd() . '/tmp');
before
session_start();
if you are using Apache web server, the quick fix is to go to your command line and type:
open /etc/apache2/
then from the window opened, open the file called httpd.conf and search for User or Group change these 2 lines to:
User _www
Group _www
This is because you want your server to have permission to your systems directories, especially you want to change the User or you can leave your Group to either staff or admin.
I had the same problem of permission, but on /var/lib/php/session/.
To fix it, I deleted the file and restarted php-fpm.
rm -rf /var/lib/php/session/sess_p930fh0ejjkeeiaes3l4395q96
sudo service php5.6-fpm restart
Now all works well.
For me the problem seems to be a WHM bug!
I have a bunch of add on domains and all work fine but with a subdomain it brings this error.
Strange thing but if I use the full URL with the main domain it works fine:
main-domain.com/my.subdomain.com
If I use the subdomain directly it brings "Permission denied (13)":
my.subdomain.com
The thing is all addon domains root is:
/home/xx/
But for my subdomain, don't know why, the root is: (I shouldn't have access to that dir)
/
So it´s really trying to reach: /tmp instead of /home/xx/tmp
Which also exists but don't have the right permissions
To clarify this are examples of the whole path:
/home/my-account/public_html
/home/my-account/tmp
/tmp
The workaround I used was:
session_save_path('/home/my-account/tmp');
session_start();
Using PHP 5.6 I had already used session_save_path() to point to a directory within the domain's structure. It worked fine until I upgraded to PHP 7.0, at which time I received the noted error. At PHP.net I found several comments that indicated assigning a direct path didn't always work, so I used their suggestion.
session_save_path(realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));
worked perfectly. Remember to change /../session to the relative location of your actual session directory.
If :
session.gc_probability > 0
session files are created by different user(s) (e.g. root and apache).
session files are all stored in the same place (e.g. /var/lib/php/session)
Then you'll see this error when e.g. the Apache PHP process attempts to run garbage collection on the session files.
Fixes :
Reconfigure PHP so gc_probability is 0, and have a cron job removing the old/stale file(s).
Have each different user save their session files in separate place(s) (session_save_path() etc).
I initially had this issue due to nginx owning the /tmp location and php-fpm was running under 'apache' user and group due to the www.conf. I swapped out the user/group in that file and then it worked ok. You may want to check <?php echo exec('whoami'); ?> to verify.
In my case the problem was SELINUX not allowing this.
A helpful command to get suggestions on how to fix this:
sealert -a /var/log/audit/audit.log
If you want to rule out SELINUX, try disabling it for a moment. If that fixes the issue then that is the problem.

Help with PHP Session Start

my program gives me this error, - Warning-PHP Function_start(); C:/PHp\tmp no such file or directory.
What do i do?
the session save thingy is pointing to windows temp.
Thank You
This basically means, that PHP is trying to store the session data in a directory which doesn't exist. Make sure that C:/PHP/tmp is actually a valid directory.
double check that the session save path (c:\PHP\tmp) is a valid directory. Also you can check php.ini and look at the session.save_path config option to see what it is set to. You might need to change it to another folder.
Make sure your files inside that directory are not corrupted. Have you edited these files at all? Check if all the files are there what should be there.

Warning: session_start() failed: No such file or directory

I'm trying to install berta (v 0.6.3b) and I get this error:
Warning: session_start() [function.session-start]:
open(/var/php_sessions/sess_a0d6b8422181739d10066fb60cebfe5d, O_RDWR)
failed: No such file or directory (2) in
/hermes/bosweb/web010/b100/ipg.ellieniemeyercom/engine/_classes/class.bertasecurity.php
on line 75 The error seems to happen on line 75 of class.bertasecurity.php (view source code)
What is wrong and how can I fix it?
Make sure that session directory is writable or you can set a path yourself with:
session_save_path
This comment is also useful if you are using above function.
I think the folder containing the session data cannot be accessed by the PHP process.
If you have not touched your php.ini, the default session.save_handler should be files (which means that session data will be stored in a folder on your file system). The value of session.save_path contains that folder, you should check that it exists and its permissions for your php process.
If you're changing the path that is being used for sessions.
You also might consider, fixing this problem by changing session.save_path variable in your php.ini file.
Then you'll be fixing in your configuration file and not only in your script.
Sessions are saved on the harddisk of your server. Most likely your session save path does not exist. Try setting it to a directory that does exist or that you have read/write rights to.
We encountered this problem when migrating a website from a cPanel server to a different host.
The session.save_path was configured in php.ini and .user.ini inside our public_html/ folder, and was presumably overwriting a default path the host would have wanted to use.
We decided the files were not needed at all, just a hangover from the old server, and deleted/renamed them out of the way, and this fixed the problem.

Can you help me locate PHP session files?

I have a default configuration of xampp (LAMP) on a windows system, I have been googleing and reading stackflow for an hour but I can not find where php session data is saved, I would like to locate a session file and look at it.
Some sites say windows usually stores it here C:\windows\tmp\ but I was unable to find it there or anywhere else.
Do you know where sessions are saved
by default?f
Do you know what kind name and file?
extension they might would have?
session_save_path() - they have no extension, they are long string UID named files.
To find the "for sure" location, do the following:
Boot up a cmd prompt
Run php --ini and find the loaded configuration file
Open the config file and search for 'session.save_path'
That's the path your session files should be saved to.
This assumes that session.save_handler is set to 'files', of course, and isn't overridden anywhere in your code.
By default, it's probably "C:\WINDOWS\Temp". The filenames are generally prefixed with sess_, and do not have an extension.
Edit: Other posters are correct in using session_save_path() to find the path as well. That's probably a more foolproof method, in case there's differences between your CLI configuration and your web configuration. I'll hand out some +1's. :D
I find this command the easiest:
php -i | grep session.save_path
CTRL + F (windows Find)... search your XAMPP dir for files modified today (by date)...
Make a php test page. If you haven't done this before simply save the following as a .php file
<?php phpinfo(); ?>
Look for session_save_path under the session section.
If it is set, this should tell you your session path.
You can find where the sessions are stored for the current configuration by calling session_save_path() - this corresponds to the configuration setting session.save_handler as zombat says. The files I think are named by prefixing the session id with 'sess_'
Find Session files in Linux machine
Copy the session cookie from your browser (press F12 and tab to cookies field)
Use grep command with your session cookie value, It will show you the session file name
grep -ir "d79c67d3615b5d208680d51c1c023a6301437715444"
On my xampp session files are directly in "xampp/tmp" location.
Session files starts with prefix "sess_" and then hexadecimal hash.

Categories