session_save_path() does not seem to work on local host
Posted by: andreea115 (---.cluster-j.websense.net)
Date: March 04, 2015 03:21PM

Hello

i am trying to work out if i need to adjust my settings in the php.ini file when i want to use the

session_save_path();

to change the default path where sessions are stored.

I ask because when i use the session_save_path() function on a LIVE SITE to save the path where data for the current session is saved it works perfectly. i.e

session_save_path('http://www.testSite.com/admin/tmp/')


However , i am having problems when i use it on my local host

session_save_path('http://localhost/testSite/admin/tmp/')


it initaly saves the session variables to the correct directory but then when i flick to another page using header('Location: ' . $url); the saved session variable disappears.

the page i relocated to also uses the same:

session_save_path('http://localhost/testSite/admin/tmp/')

and there is nothing on the page that will delete the session variables.

so, i am unclear why the session variables are being deleted.

would appricate any help or advice.

Options: ReplyQuote
Re: session_save_path() does not seem to work on local host
Posted by: Otomatic (Moderator)
Date: March 04, 2015 03:57PM

Hi,

A "path", not an "url". See php documention
By default, it is :
session.save_path = "C:/wamp/tmp"

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: session_save_path() does not seem to work on local host
Posted by: RiggsFolly (---.as43234.net)
Date: March 04, 2015 03:59PM

Before I get into a long description of how bad an idea doing this is, can I ask why you feel the need to use that php statement please?

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: session_save_path() does not seem to work on local host
Posted by: andreea115 (---.cluster-j.websense.net)
Date: March 04, 2015 04:03PM

HI RiggsFolly

Really sorry. what php statement are you referring to ?

Options: ReplyQuote
Re: session_save_path() does not seem to work on local host
Posted by: RiggsFolly (---.as43234.net)
Date: March 04, 2015 04:07PM

Well Eerrrr session_save_path

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: session_save_path() does not seem to work on local host
Posted by: andreea115 (---.cluster-j.websense.net)
Date: March 04, 2015 04:24PM

hi RiggsFolly

its a legacy site. I have joined the project late. so, the session save_path was implimented before i joined.

But i presumed that they used the session_save_path() because they were using diffrent page headers on diffrent pages of the site and therefore wanted a central location for all the sessions

Options: ReplyQuote
Re: session_save_path() does not seem to work on local host
Posted by: Otomatic (Moderator)
Date: March 04, 2015 04:51PM

Hi,

WARNING. see difference between _ and .

session_save_path ([ string $path ] ) is for php script and before session_start()

session.save_path = string is a directive for php.ini

But for the two case the string should be a path, not an url.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: session_save_path() does not seem to work on local host
Posted by: andreea115 (---.cluster-j.websense.net)
Date: March 04, 2015 05:07PM

Hi Otomatic

i made the change to a path but it still does not work.

i placed this ; session_save_path("C:/wamp/tmp"winking smiley;


before the session_start() .

I also tried not placing a session_save_path() on the script but the values are still being deleted once i change pages.

i know that the C:/wamp/tmp does indeed intially saving those values buecase when i did a

echo '<pre>';
var_dump($_SESSION);
echo '</pre>';

on the first page in which the session variables were saved, it saved them. However, when i then swithed to anotehr page all the values vanished.

Options: ReplyQuote
Re: session_save_path() does not seem to work on local host
Posted by: RiggsFolly (---.as43234.net)
Date: March 04, 2015 05:12PM

Ok so

session_save_path() should use a path and not a url i.e. session_save_start('admin/tmp');

It should not be coded in any way that will make the code difficult to move i.e. like yours


When I test this code
<?php
    session_save_path('http://testing.localhost/session/tmp/');
    $ok = session_start();
?>
<!doctype html>
<html >
<head>
    <meta charset="UTF-8">
    <title>Test</title>
</head>
<body>
<?php
echo $ok ? 'session OK' : 'session FAILED';
?>
</body>
</html>

'testing.localhost' is a valid Virtual Host domain on my system and the subfolder 'session/tmp' exists.
You should check that whatever folder you use actually exists or this will not work

I get these errors in my 'php error log'

[04-Mar-2015 15:57:36 Europe/London] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: open(http://testing.localhost/session/tmp/\sess_rs8fb9ag93gq6h6e2g52a01or6, O_RDWR) failed: Invalid argument (22) in D:\websrc\www\testing\test.php on line 4
[04-Mar-2015 15:57:36 Europe/London] PHP Stack trace:
[04-Mar-2015 15:57:36 Europe/London] PHP   1. {main}() D:\websrc\www\testing\test.php:0
[04-Mar-2015 15:57:36 Europe/London] PHP   2. session_start() D:\websrc\www\testing\test.php:4
[04-Mar-2015 15:57:36 Europe/London] PHP Warning:  Unknown: open(http://testing.localhost/session/tmp/\sess_rs8fb9ag93gq6h6e2g52a01or6, O_RDWR) failed: Invalid argument (22) in Unknown on line 0
[04-Mar-2015 15:57:36 Europe/London] PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (http://testing.localhost/session/tmp/) in Unknown on line 0
[04-Mar-2015 15:57:37 Europe/London] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: open(http://testing.localhost/session/tmp/\sess_rs8fb9ag93gq6h6e2g52a01or6, O_RDWR) failed: Invalid argument (22) in D:\websrc\www\testing\test.php on line 4
[04-Mar-2015 15:57:37 Europe/London] PHP Stack trace:
[04-Mar-2015 15:57:37 Europe/London] PHP   1. {main}() D:\websrc\www\testing\test.php:0
[04-Mar-2015 15:57:37 Europe/London] PHP   2. session_start() D:\websrc\www\testing\test.php:4
[04-Mar-2015 15:57:37 Europe/London] PHP Warning:  Unknown: open(http://testing.localhost/session/tmp/\sess_rs8fb9ag93gq6h6e2g52a01or6, O_RDWR) failed: Invalid argument (22) in Unknown on line 0
[04-Mar-2015 15:57:37 Europe/London] PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (http://testing.localhost/session/tmp/) in Unknown on line 0


So I would bet that if you looked on your LIVE system you would be getting them there as well. If not I would bet that the previous coders have turned OFF error_reporting in some way in order to hide there mistakes.


If I code it like this

<?php
    session_save_path('session/tmp/');
    $ok = session_start();
?>
<!doctype html>
<html >
<head>
    <meta charset="UTF-8">
    <title>Test</title>
</head>
<body>
<?php
echo $ok ? 'session OK' : 'session FAILED';
?>
</body>
</html>

It works perfectly and session files are created in the 'session/tmp/' folder.



I guess the first thing you can do on this system is correct this error.
Also I would make sure that you have these setting in your php.ini

display_errors = On
log_errors = On
error_log = "c:/wamp/logs/php_error.log"

Of course you may find that the system has so many errors that you have to turn this option Off
display_errors = Off

Then the errors will only get written to the "c:/wamp/logs/php_error.log" and not the browser.

And you should take regular looks at the "c:/wamp/logs/php_error.log"

So you can see all the other errors generated by this system.

Also remember that every script that wants to use this OTHER session store has to set the session_save_path() before doing a start_session() Otherwise it will be looking for its session files in the wrong place.

session_save_path('session/tmp/');
start_session()

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-



Edited 2 time(s). Last edit at 03/04/2015 05:14PM by RiggsFolly.

Options: ReplyQuote


Sorry, only registered users may post in this forum.