views:

24

answers:

3

I have a site which I have been testing in a sub-folder of my client's site-root. I had no log in problems during testing, but then I moved the new site files from a sub-directory to the main site root, and now I'm losing my logged in state after almost every page refresh in secure areas.

I am running a $_session based login system that refreshes the session id on every page load, with a comparison value stored in the MySQL database.

Does anyone have suggestions for what could be causing this problem?

A: 

Cookies are usually path relevant. Your previous sub-directory based site was probably setting the cookie (that binds the browser to the user) only for that sub-directory.

A way to fix it is to put a redirection page on the old subdir that adds a cookie to '/' and then redirects to new site on root.

krico
Not sure I follow. That sub-directory will not exist in the final deployment.
YsoL8
A cookie in a browser is usualy set for a specific path, so that for example the pages under /web-app-one cannot read the cookies from /web-app-two.
krico
session.cookie_path is set to / in phpinfo. That sounds right since all the security stuff in handled in one folder.
YsoL8
A: 

If you change session id you will loose all data stored in previous session. You must set session name after every session start command

<?php
session_name('AnySessName');
?>

or use other mechanism to store your variables cross sessions.

GOsha
Sorry, I mean a value called $_session['id']. Does this still apply?
YsoL8
ok. You can write`<?php Echo $_COOKIE['UserSess']; ?>`on your page.Is it changed after reloading page?Browser is storing session identificator in cookies
GOsha
that is not returning anything!
YsoL8
ok. and if write <?php error_reporting(15);?> before session start wil it returns any errors? looks like seeion not started at all. or lost session. are other variables from session seen?
GOsha
Error reporting isn't showing anything up
YsoL8
sorry. You must call session_name BEFORE you start session)))I think that you have a new session every time reloaded page.put <?php Echo session_name(); ?> and refresh several times. Is that value chenged?
GOsha
Now I'm seeing UserSess echoed.
YsoL8
Is it new every time or staying the same?Now write instead $_COOKIE['UserSess']; $_SESSION['id'];is it changed? if yes - check changing or placing conditions in your code.
GOsha
is that code correct?
YsoL8
sorry for my english)))now we check if SESSION var reachable. What error it returns?
GOsha
echoing $_COOKIE['UserSess']; or $_SESSION['id']; returns nothing!
YsoL8
seems session not reachable or started.
GOsha
+1  A: 

krico was right in suggesting that the cookie path may be the cause (but the solution proposed seems a bit daft) however you've said that is not the case.

Check to see exactly what cookies (name, path, expiry, flags) are being set and returned by using iehttpheaders (MSIE) LiveHeaders (Firefox) or using a network sniffer like wireshark. Then ask the question again providing details of what you found out.

C.

symcbean
as requested at http://stackoverflow.com/questions/2965878/intermitant-sessions
YsoL8