Strange Sessions Issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
harrillj
Forum Newbie
Posts: 4
Joined: Tue May 24, 2005 3:55 pm

Strange Sessions Issue

Post by harrillj »

Hello,

I have two identical sites hosted with two different ISPs; one has login/logout issues, the other does not. The only difference is there is a PHP Conncetion file that points to the MySQL database at each hosting server. The databases are identical, same name, same tables, it was a copy.

The fully functional site was uploaed to the other hosting company server. I then changed the 4 connection variables on my connection PHP file; 1-MySQL DB server name, 2-database name, 3-user name, 4-password. Other than that, every line of code is identical between the sites. I even ran them through source code compare tools.

I am having various auto-logout issues. One example is that when I add to the shopping cart by clicking the add-to-cart button, I end up on the add-to-cart page as I should but I have a "your shopping cart is empty", and I am now logged out. My site requires the user to be logged in to buy.

Another example is when a new user registers they are auto-logged in. On one site this works fine, on the other site after registering they are directed to the login page indicating the auto-login failed.

I positive the code and databases are identical between the sites.

Has anyone ever experienced this before? Any suggestions? I was thinking that the PHP server settings are different on the two servers, so I created a PHP info page and compared them side by side, but I simply do not have the skills to know what setting could cause these session issues and the auto-logout. I have been on this for almost 2 weeks and simply have to get this done.

Thanks in advance
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

a) post code
b) are the 2 diffrent "servers" on the same computer (i.e. on your computer) maybe the session are on the same computer is what im saying (its not likley but maybe?)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

My first guess is that your code generates a cookie for domain1. Which could explain why it isn't working for domain2 ;)
harrillj
Forum Newbie
Posts: 4
Joined: Tue May 24, 2005 3:55 pm

Post by harrillj »

Hello and thanks for the response. I am not clear on why the cookie would work on one domain but not the other. The code is identical on both sites, just different servers and ISPs. Cookies popped in my mind as a possibility because I know they are required for logging in. I just don't understand what would allow it to work on one but not the other.

I added a page on the working site and also one on the non-working site to display the PHP Info. The working site is http://www.title-insurance-search.com and the site with identical code that does not work and is hosted at a diferent ISP is http://www.appraiser-search.com. In the lower middle of each home page to the right of the "Sign Up Now" button there is a "go" link. Clicking on that displays the PHP Info page.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

when a cookie is set, you have to specify which domain the cookie is available to, and that cookie will only be available on that domain
cgchris99
Forum Newbie
Posts: 5
Joined: Thu Jun 02, 2005 7:35 pm

Post by cgchris99 »

Did you ever figure out what was happening. I have something similar happening to me.
harrillj
Forum Newbie
Posts: 4
Joined: Tue May 24, 2005 3:55 pm

Post by harrillj »

Yes I did.. after 3 weeks of 12 hours days. It turned out to be a PHP server setting.

On the server and site that worked at midphase.com, the following PHP setting existed:

output_buffering = on

On the other 7 sites, all wth the same session issues, all on different ISPs and servers, they had it this way:

output_buffering = no value.

I had one of the ISPs change the setting, which they did with no poblem, and bam, the site worked liked a charm. I then emailed the other ISPs and most would not change the setting, and told me I had to use .htaccess file in the root directory of my site. You may already know this, but you can use the .htaccess text file to add directives to change settings locally, that is, just for your site.

If you place an .htaccess file in your root directory with the followling line, it will fix the problem I had:

php_value output_buffering 4096
cgchris99
Forum Newbie
Posts: 5
Joined: Thu Jun 02, 2005 7:35 pm

Post by cgchris99 »

Just checked mine. Already set at no value.
My problem is I'm loosing the session value very quickly.

I test by inserting records to a database after I log in. I get about 4 done before it shows that I am logged off and have to log back in. It's a pain.

The more I dig into this the stranger it is. If I run the FireFox browser, I have no problem losing the session variable. In fact it works perfectly.

The problem is only while running IE6
cgchris99
Forum Newbie
Posts: 5
Joined: Thu Jun 02, 2005 7:35 pm

Post by cgchris99 »

I now know it is an issue of a redirect causing the session variables to loose value.

I have found some code that is supposed to fix it but so far none of it makes any difference.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

post some code.
harrillj
Forum Newbie
Posts: 4
Joined: Tue May 24, 2005 3:55 pm

Post by harrillj »

It needs to be set to "on", not "no value". All of the servers that had "no value" did not work for me.

The .htaccess file with setting the value to "4096" did the trick for me.

I was able to go through a few screens OK, but most of my problems were all my redirects. As soon as I started with redirects triggered by buttons, the problems started.
cgchris99
Forum Newbie
Posts: 5
Joined: Thu Jun 02, 2005 7:35 pm

Post by cgchris99 »

I found on another site that the following code that is supposed to work.
(from file insert.php)
session_write_close();
header( "location: /thankyou.php");
exit;

The thankyou.php page has no code in it other than displaying the Clubname.
The redirect may work a couple of times and then doesn't. It is almost always 4 times and then the session loses the value and Clubname is blank.

The thankyou.php has a link that goes back to insert.php
Insert.php displays a form and writes the records to mysql database table.
very simple stuff.
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

if your problem hasn't been solved.

1. make sure you don't redirect (without the sessionid at least)
2. turn on all error reporting, if output_buffering=on helps, then you are doing something wrong causing late header modifications which are discarded.
3. are you switching in the hierachy (up and down in folders) that might cause some problems, as certain security checks might fail auotmatically discarding sessions and such.

is it always on the same side or on different?
Post Reply