Click to See Complete Forum and Search --> : [Resolved] losing cookie values under linux


ksandom
07-01-2003, 09:11 PM
Problem:
Loosing cookie values, but only under linux. No errors occur.

Setup:
Linux:
Ver: Redhat 9.0
Apache: httpd-2.0.40-21.3
MYSQL: mysql-3.23.56-1.9
PHP: php-4.2.2-17
Windows:
Ver: 98SE
Apache: 1.something (1.3.? I think)
MYSQL: ?
PHP: ?

Further info:
On a browser where cookies are not enabled, the page would add an ID to the address line, which would be placed after a question mark in the address. However, when ever the page is access under linux, it "tries " to put in this data, but it has not been set, so it doesn't get past putting a question mark there:
http://localhost/pt4/index.php?

Suspicions:
Security/policy settings
Bad compile
Apache settings
PHP settings
Version change -> different method of application?

Eliminated suspicions:
File permissions
Partition type
Client browser
Client OS

Analysis:
I beleive the problem lies in settings or a bad compile. I've been through quite a lot of diagnostics checking various settings, access rights, browsers, client OSes etc. I don't believe it is a OS problem, however I do think the problem has come about from default settings which come with the OS.

Next steps:
I'll downloaded some different versions of Apache and PHP (I don't think MYSQL is worth fiddeling with at the moment. Correct me if you disagree). I'll fiddle about with those to see what happens.

I'll update this post as changes/progress occurs. Any input would be greatfully welcomed.

ksandom
07-03-2003, 03:01 AM
As I suspected, this had nothing to do with the OS, and thus my original posting in the code section was the right place. As it turned out, when I changed over to a linux server, the version of PHP that came with the OS was significantly newer than the one I had been using under Windows.

I had been considering downgrading my version of PHP to one similar to what I had under windows, then I realised what a stupid idea that was and decided to do more exploration into how it should be done under the 2.3.x versions and beyond of PHP. After browsing some forums around phpbuilder, I found some links to:
http://ca3.php.net/manual/en/ref.session.php
http://ca3.php.net/manual/en/function.session-start.php
which had been recommened by another user. The first example in the first link was a big help.

Here is a working example which is based off the original example which I first used to learn about cookies a while back. I've adapted it to work with the newer versions of PHP. If people have suggestions for improvements, feel free to suggest away:

index.php (and nextpage.php (I just created a symbolic link to index.php)):

<?php
session_start();
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
} else {
$_SESSION['count']++;
}
$count=$_SESSION['count'];

print("<html><head><title>Test area</title></head><body>");
?>

<p>Hello visitor, you have seen this page <? echo $count; ?> times.</p><p>
<p>To continue,
<A HREF="index.php?<?=SID?>">click here</A><br>
<a href="nextpage.php?<?=SID?>">next page</a><br>
<a href="logout.php?<?=SID?>">Logout</a>
</p></body></html>


logout.php:

<?php
session_start();
unset($_SESSION['count']);
?>
<a href="index.php">Return</a>


Note that index.php and nextpage.php come from the same code. This is basically to demonstraight that the cookies are working accross different pages.

And now.... the final frontier.... to put this into the main project. Somewhere in the distance their echos a fait sound "Mwau ha ha haaaa!"

stolzyboy
07-03-2003, 01:25 PM
most likely that only real problem was that the new server had

register_globals = Off

instead of

register_globals = On

ksandom
07-03-2003, 11:55 PM
I grabbed this from phpinfo.php:
register_globals Off Off

I think I will stick with adapting my code, because that way it will be more portable. Since this seems to be a default setting under Redhat. There must be a reason that this setting would be defaulted to off? Performance maybe?

I'm guessing that this setting would be changed at compile time?

btw: How do I tag my thread as solved? I saw the option when I first joined, but I haven't been able to find it since.

ksandom
07-04-2003, 10:43 PM
I'm applying the changes back in to the main project. However, this register_globals setting seems to be influencing many areas. If I understand it correctly, register_globals being off would mean that when I have a line like:
global $varname;
$varname would not actually be getting or setting to the global space where all the other functions can access it.

So what I wan't to know is:
- Am I understanding this correctly?
- How do I change the setting?
- Could this turned off as encouragement to use OO?
- Can it be turned on and off on the fly/at run time?

ksandom
07-05-2003, 08:35 AM
Right, all the crutial stuff is working now. I only have a few tidy up things to do now.

The things that have helped me upgrade the code for the newer versions of PHP are:

Removing globals and replacing them with:
$_SESSION['varname']
$_POST['varname']


http://www.etronicscomputers.com/docs/phpforbeginners.htm
This site helped set me on track with the login script.